blob: d09299a583129ec4b0b0ca8c814b92c09e60b296 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
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)
Travis Sheltone34d0e32024-07-30 21:08:56 +020029" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010030" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000031" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010032" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000033" Permission is hereby granted to use and distribute this code,
34" with or without modifications, provided that this copyright
35" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000036" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000037" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000038" expressed or implied. By using this plugin, you agree that
39" in no event will the copyright holder be liable for any damages
40" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010041"
42" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
43" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
44"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020045"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000046"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000047" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000048" (James 1:22 RSV)
49" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000050" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000051if &cp || exists("g:loaded_netrw")
52 finish
53endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020054
55" Check that vim has patches that netrw requires.
56" Patches needed for v7.4: 1557, and 213.
57" (netrw will benefit from vim's having patch#656, too)
58let s:needspatches=[1557,213]
59if exists("s:needspatches")
60 for ptch in s:needspatches
61 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
62 if !exists("s:needpatch{ptch}")
63 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
64 endif
65 let s:needpatch{ptch}= 1
66 finish
67 endif
68 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020069endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020070
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010071let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000072
Bram Moolenaar1afcace2005-11-25 19:54:28 +000073let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010074setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020075"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010076"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010077"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000079" ======================
80" Netrw Variables: {{{1
81" ======================
82
Bram Moolenaar071d4272004-06-13 20:20:40 +000083" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020084" netrw#ErrorMsg: {{{2
85" 0=note = s:NOTE
86" 1=warning = s:WARNING
87" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010088" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
89" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
90" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010091" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020092fun! netrw#ErrorMsg(level,msg,errnum)
93" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
94
95 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020096" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020097 return
98 endif
99
100 if a:level == 1
101 let level= "**warning** (netrw) "
102 elseif a:level == 2
103 let level= "**error** (netrw) "
104 else
105 let level= "**note** (netrw) "
106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100107" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200108
Damienb4d11642024-08-15 22:00:45 +0200109 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200110 " use popup window
111 if type(a:msg) == 3
112 let msg = [level]+a:msg
113 else
114 let msg= level.a:msg
115 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200116 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200117 let s:popuperr_text= ""
118 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119 " (default) netrw creates a one-line window to show error/warning
120 " messages (reliably displayed)
121
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100122 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100124" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125
126 " getting messages out reliably is just plain difficult!
127 " This attempt splits the current window, creating a one line window.
128 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100129" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100131" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100133 if type(a:msg) == 3
134 for msg in a:msg
135 NetrwKeepj call setline(line("$")+1,level.msg)
136 endfor
137 else
138 NetrwKeepj call setline(line("$")+1,level.a:msg)
139 endif
140 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100142" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 bo 1split
144 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200145 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100147 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100148" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200149 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100150 if type(a:msg) == 3
151 for msg in a:msg
152 NetrwKeepj call setline(line("$")+1,level.msg)
153 endfor
154 else
155 NetrwKeepj call setline(line("$"),level.a:msg)
156 endif
157 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200158 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100159" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200160 if &fo !~ '[ta]'
161 syn clear
162 syn match netrwMesgNote "^\*\*note\*\*"
163 syn match netrwMesgWarning "^\*\*warning\*\*"
164 syn match netrwMesgError "^\*\*error\*\*"
165 hi link netrwMesgWarning WarningMsg
166 hi link netrwMesgError Error
167 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100168" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200169 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200170
171 else
172 " (optional) netrw will show messages using echomsg. Even if the
173 " message doesn't appear, at least it'll be recallable via :messages
174" redraw!
175 if a:level == s:WARNING
176 echohl WarningMsg
177 elseif a:level == s:ERROR
178 echohl Error
179 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100180
181 if type(a:msg) == 3
182 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100183 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100184 endfor
185 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100186 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100187 endif
188
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100189" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200190 echohl None
191 endif
192
193" call Dret("netrw#ErrorMsg")
194endfun
195
196" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100197" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100198" Loosely, varname = value.
199fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100200" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100201 if !exists(a:varname)
202 if type(a:value) == 0
203 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200204 elseif type(a:value) == 1 && a:value =~ '^[{[]'
205 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206 elseif type(a:value) == 1
207 exe "let ".a:varname."="."'".a:value."'"
208 else
209 exe "let ".a:varname."=".a:value
210 endif
211 endif
212endfun
213
214" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000215" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200216call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000217if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100218 call s:NetrwInit("s:THINLIST",0)
219 call s:NetrwInit("s:LONGLIST",1)
220 call s:NetrwInit("s:WIDELIST",2)
221 call s:NetrwInit("s:TREELIST",3)
222 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000223endif
224
Damien7c754112024-08-15 21:58:57 +0200225let s:NOTE = 0
226let s:WARNING = 1
227let s:ERROR = 2
228call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
229
Bram Moolenaar9964e462007-05-05 17:54:07 +0000230" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200231" Default option values: {{{2
232let g:netrw_localcopycmdopt = ""
233let g:netrw_localcopydircmdopt = ""
234let g:netrw_localmkdiropt = ""
235let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200236
237" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000238" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200239if exists("*popup_atcursor")
240\ && has("syntax")
241\ && exists("g:syntax_on")
242\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200243 call s:NetrwInit("g:netrw_use_errorwindow",2)
244else
245 call s:NetrwInit("g:netrw_use_errorwindow",1)
246endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200247
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000248if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100249 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000250 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100251 elseif executable("curl")
252 let g:netrw_dav_cmd = "curl"
253 else
254 let g:netrw_dav_cmd = ""
255 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000257if !exists("g:netrw_fetch_cmd")
258 if executable("fetch")
259 let g:netrw_fetch_cmd = "fetch -o"
260 else
261 let g:netrw_fetch_cmd = ""
262 endif
263endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100264if !exists("g:netrw_file_cmd")
265 if executable("elinks")
266 call s:NetrwInit("g:netrw_file_cmd","elinks")
267 elseif executable("links")
268 call s:NetrwInit("g:netrw_file_cmd","links")
269 endif
270endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000271if !exists("g:netrw_ftp_cmd")
272 let g:netrw_ftp_cmd = "ftp"
273endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200274let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200275if !exists("g:netrw_ftp_options")
276 let g:netrw_ftp_options= "-i -n"
277endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000278if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100279 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100280 let g:netrw_http_cmd = "wget"
281 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100282 elseif executable("curl")
283 let g:netrw_http_cmd = "curl"
284 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200285 elseif executable("elinks")
286 let g:netrw_http_cmd = "elinks"
287 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000288 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100289 let g:netrw_http_cmd = "fetch"
290 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200291 elseif executable("links")
292 let g:netrw_http_cmd = "links"
293 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000294 else
295 let g:netrw_http_cmd = ""
296 endif
297endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100298call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100299call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100300call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
301call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200302call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200303if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200304 if executable("scp")
305 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
306 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200307 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200308 else
309 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
310 endif
311endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100312call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
313call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000314
Nir Lichtman1e34b952024-05-08 19:19:34 +0200315if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000316 \ && exists("g:netrw_use_nt_rcp")
317 \ && g:netrw_use_nt_rcp
318 \ && executable( $SystemRoot .'/system32/rcp.exe')
319 let s:netrw_has_nt_rcp = 1
320 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000321else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000322 let s:netrw_has_nt_rcp = 0
323 let s:netrw_rcpmode = ''
324endif
325
326" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000327" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000328" Cygwin Detection ------- {{{3
329if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200330 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
331 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000332 else
333 let g:netrw_cygwin= 0
334 endif
335endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000336" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100337call s:NetrwInit("g:netrw_alto" , &sb)
338call s:NetrwInit("g:netrw_altv" , &spr)
339call s:NetrwInit("g:netrw_banner" , 1)
340call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200341call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200343call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100344call s:NetrwInit("g:netrw_compress" , "gzip")
345call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200346if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
347 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
348 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000349endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200350call s:NetrwInit("g:netrw_cursor" , 2)
351let s:netrw_usercul = &cursorline
352let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200353"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100354call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000355" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200356call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200357call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200358call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100359call s:NetrwInit("g:netrw_dirhistmax" , 10)
360call s:NetrwInit("g:netrw_fastbrowse" , 1)
361call 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 +0000362if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
364 let g:netrw_ftp_list_cmd = "ls -lF"
365 let g:netrw_ftp_timelist_cmd = "ls -tlF"
366 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000367 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000368 let g:netrw_ftp_list_cmd = "dir"
369 let g:netrw_ftp_timelist_cmd = "dir"
370 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000371 endif
372endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100373call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000374" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100375call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000376if !exists("g:netrw_ignorenetrc")
377 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
378 let g:netrw_ignorenetrc= 1
379 else
380 let g:netrw_ignorenetrc= 0
381 endif
382endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100383call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000384if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000385 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100386 if exists("g:netrw_list_cmd_options")
387 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
388 else
389 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
390 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000391 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200392 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100393 if exists("g:netrw_list_cmd_options")
394 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
395 else
396 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
397 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000398 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100399" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000400 let g:netrw_list_cmd= ""
401 endif
402endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100403call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000404" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200405if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200406 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200407 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
408endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100409if !exists("g:netrw_localcmdshell")
410 let g:netrw_localcmdshell= ""
411endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000412if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200413 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000414 if g:netrw_cygwin
415 let g:netrw_localcopycmd= "cp"
416 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000417 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200418 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000419 endif
420 elseif has("unix") || has("macunix")
421 let g:netrw_localcopycmd= "cp"
422 else
423 let g:netrw_localcopycmd= ""
424 endif
425endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100426if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200427 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200429 let g:netrw_localcopydircmd = "cp"
430 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000432 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200433 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200435 elseif has("unix")
436 let g:netrw_localcopydircmd = "cp"
437 let g:netrw_localcopydircmdopt= " -R"
438 elseif has("macunix")
439 let g:netrw_localcopydircmd = "cp"
440 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100441 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200442 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100443 endif
444endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200445if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100446 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200447 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
448endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200449if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200450 if g:netrw_cygwin
451 call s:NetrwInit("g:netrw_localmkdir","mkdir")
452 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000453 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200454 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200455 endif
456else
457 call s:NetrwInit("g:netrw_localmkdir","mkdir")
458endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200459call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200460if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200461 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200462 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
463endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000464if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200465 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000466 if g:netrw_cygwin
467 let g:netrw_localmovecmd= "mv"
468 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000469 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200470 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000471 endif
472 elseif has("unix") || has("macunix")
473 let g:netrw_localmovecmd= "mv"
474 else
475 let g:netrw_localmovecmd= ""
476 endif
477endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100478" following serves as an example for how to insert a version&patch specific test
479"if v:version < 704 || (v:version == 704 && !has("patch1107"))
480"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
482" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000483if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000484 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000485endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000486if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000487 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
488endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000489" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
491call s:NetrwInit("g:netrw_maxfilenamelen", 32)
492call s:NetrwInit("g:netrw_menu" , 1)
493call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200494call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495call s:NetrwInit("g:netrw_retmap" , 0)
496if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
497 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200498elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100499 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
500else
501 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000502endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100503call s:NetrwInit("g:netrw_preview" , 0)
504call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100505call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100506call s:NetrwInit("g:netrw_sshport" , "-p")
507call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
508call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
509call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100510call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
511" Default values - q-s ---------- {{{3
512call s:NetrwInit("g:netrw_quickhelp",0)
513let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100514 \ "(create new) %:file d:directory",
515 \ "(windows split&open) o:horz v:vert p:preview",
516 \ "i:style qf:file info O:obtain r:reverse",
517 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
518 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
519 \ "(history) qb:list u:go up U:go down",
520 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
522call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100523if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
524 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
525else
526 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
527endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
529call s:NetrwInit("g:netrw_sort_options" , "")
530call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000531if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100532 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200533 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534 else
535 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000536 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000537endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538call s:NetrwInit("g:netrw_special_syntax" , 0)
539call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200540call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100541call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100542call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000543" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200545if !exists("g:netrw_xstrlen")
546 if exists("g:Align_xstrlen")
547 let g:netrw_xstrlen= g:Align_xstrlen
548 elseif exists("g:drawit_xstrlen")
549 let g:netrw_xstrlen= g:drawit_xstrlen
550 elseif &enc == "latin1" || !has("multi_byte")
551 let g:netrw_xstrlen= 0
552 else
553 let g:netrw_xstrlen= 1
554 endif
555endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100556call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200557call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100558call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200559if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000560" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000561" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100562call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200563if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200564 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200565else
Bram Moolenaarff034192013-04-24 18:51:19 +0200566 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200567endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200568call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100569call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
570call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100571if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100572 let s:treedepthstring= "│ "
573else
574 let s:treedepthstring= "| "
575endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200576call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000577
578" BufEnter event ignored by decho when following variable is true
579" Has a side effect that doau BufReadPost doesn't work, so
580" files read by network transfer aren't appropriately highlighted.
581"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582
Bram Moolenaaradc21822011-04-01 18:03:16 +0200583" ======================
584" Netrw Initialization: {{{1
585" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200586if 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 +0100587" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100588 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200589" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100590 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100591 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
592 au VimEnter * let s:initbeval= &beval
593"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100594" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
595" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
596" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
597" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
598" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
599" 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 +0200600endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200601au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200602
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200603if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100604 com! -nargs=* NetrwKeepj keepj <args>
605else
606 let g:netrw_keepj= ""
607 com! -nargs=* NetrwKeepj <args>
608endif
609
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000610" ==============================
611" Netrw Utility Functions: {{{1
612" ==============================
613
Bram Moolenaaradc21822011-04-01 18:03:16 +0200614" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100615" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100616if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100617" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100618 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100619 if &ft != "netrw"
620 return ""
621 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200622 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
623 " popup error window is still showing
624 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
625 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
626 " text under mouse hasn't changed; only close window when it changes
627 call popup_close(s:popuperr_id)
628 unlet s:popuperr_text
629 else
630 let s:popuperr_text= v:beval_text
631 endif
632 let mesg= ""
633 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 +0100634 let mesg= ""
635 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
636 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
637 elseif getline(v:beval_lnum) =~ '^"\s*/'
638 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
639 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100640 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100641 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
642 let mesg = "S: edit sorting sequence"
643 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
644 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
645 elseif v:beval_text == "Quick" || v:beval_text == "Help"
646 let mesg = "Help: press <F1>"
647 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
648 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
649 else
650 let mesg= ""
651 endif
652 return mesg
653 endfun
654"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100655" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
656" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
657" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
658" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
659" 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 +0200660endif
661
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200663" netrw#Explore: launch the local browser in the directory of the current file {{{2
664" indx: == -1: Nexplore
665" == -2: Pexplore
666" == +: this is overloaded:
667" * If Nexplore/Pexplore is in use, then this refers to the
668" indx'th item in the w:netrw_explore_list[] of items which
669" matched the */pattern **/pattern *//pattern **//pattern
670" * If Hexplore or Vexplore, then this will override
671" g:netrw_winsize to specify the qty of rows or columns the
672" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100673" 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 +0200674" dosplit==1: the window will be split before running the local browser
675" style == 0: Explore style == 1: Explore!
676" == 2: Hexplore style == 3: Hexplore!
677" == 4: Vexplore style == 5: Vexplore!
678" == 6: Texplore
679fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100680" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100681" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200682 if !exists("b:netrw_curdir")
683 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100684" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200685 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100686
687 " record current file for Rexplore's benefit
688 if &ft != "netrw"
689 let w:netrw_rexfile= expand("%:p")
690 endif
691
692 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200693 let curdir = simplify(b:netrw_curdir)
694 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200695 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200696 let curdir= substitute(curdir,'\','/','g')
697 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100698" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100699
700 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
701 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
702 " try Explore again.
703 if a:0 > 0
704" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100705 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
706 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
707 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
708 \ '~'.expand("<slnum>"))
709 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200710 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
711 if a1 != a:1
712 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
713 return
714 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100715 endif
716 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200717
718 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200719 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100720" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100721 sil! let keepregstar = @*
722 sil! let keepregplus = @+
723 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200724 sil! let keepregslash= @/
725
Bram Moolenaar8d043172014-01-23 14:24:41 +0100726 " if dosplit
727 " -or- file has been modified AND file not hidden when abandoned
728 " -or- Texplore used
729 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200730 call s:SaveWinVars()
731 let winsz= g:netrw_winsize
732 if a:indx > 0
733 let winsz= a:indx
734 endif
735
736 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200737 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200738 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200739 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200741 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200744 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200747 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200748 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200749 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200752 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200753 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200754 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200758 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200759 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200764 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200765
766 elseif a:style == 6 " Texplore
767 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 exe "keepalt tabnew ".fnameescape(curdir)
769 call s:RestoreBufVars()
770 endif
771 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100773 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200774
775 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
784 if dirname !~ '/$'
785 let dirname= dirname."/"
786 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200792 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= a:1
799 endif
800 else
801 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 call s:NetrwClearExplore()
804" call Dret("netrw#Explore : cleared list")
805 return
806 endif
807
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 if dirname =~ '\.\./\=$'
810 let dirname= simplify(fnamemodify(dirname,':p:h'))
811 elseif dirname =~ '\.\.' || dirname == '.'
812 let dirname= simplify(fnamemodify(dirname,':p'))
813 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815
816 if dirname =~ '^\*//'
817 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
820 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
823
824 elseif dirname =~ '^\*\*//'
825 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 let pattern= substitute(dirname,'^\*\*//','','')
828 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830
831 elseif dirname =~ '/\*\*/'
832 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100833" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200835 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836 let b:netrw_curdir = prefixdir
837 else
838 let b:netrw_curdir= getcwd().'/'.prefixdir
839 endif
840 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
841 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100842" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
843" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200844
845 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200846 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200847 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100848" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname=~ '^\*\*/'
851 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
852 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 else
856 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100857" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200858 endif
859
860 if starpat == 0 && a:indx >= 0
861 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 if dirname == ""
864 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200866 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200867 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200868 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200870 if dirname == ""
871 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200872 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100874 " depending on whether backslashes have been converted to forward slashes by earlier code).
875 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 let dirname= b:netrw_curdir."/".dirname
877 endif
878 elseif dirname !~ '^/'
879 let dirname= b:netrw_curdir."/".dirname
880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200882 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100883" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
884" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200885 endif
886 if exists("w:netrw_bannercnt")
887 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
888 " If one wants to return the same place in the netrw window, use :Rex instead.
889 exe w:netrw_bannercnt
890 endif
891
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100892" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200893 " ---------------------------------------------------------------------
894 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
895" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100896" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200897" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100898" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200899" endif
900 " ---------------------------------------------------------------------
901
902 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
903 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
904 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
905 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
906 elseif a:indx <= 0
907 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100908" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200909 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100910" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 let s:didstarstar= 1
912 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
913 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
914 endif
915
916 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100917" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200918 if !exists("w:netrw_explore_indx")
919 let w:netrw_explore_indx= 0
920 endif
921
922 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100923" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200924
925 if indx == -1
926 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100927" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200928 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100929 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 +0200930 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100931" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100932 if @* != keepregstar | sil! let @* = keepregstar | endif
933 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100934 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 sil! let @/ = keepregslash
936" call Dret("netrw#Explore")
937 return
938 endif
939 let indx= w:netrw_explore_indx
940 if indx < 0 | let indx= 0 | endif
941 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
942 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100943" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200944 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
945 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100946" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 endwhile
948 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950
951 elseif indx == -2
952 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100953" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100955 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 +0200956 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100957" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100958 if @* != keepregstar | sil! let @* = keepregstar | endif
959 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100960 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200961 sil! let @/ = keepregslash
962" call Dret("netrw#Explore")
963 return
964 endif
965 let indx= w:netrw_explore_indx
966 if indx < 0 | let indx= 0 | endif
967 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
968 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100969" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 while indx >= 0 && curfile == w:netrw_explore_list[indx]
971 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 endwhile
974 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976
977 else
978 " Explore -- initialize
979 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100981 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 let w:netrw_explore_indx= 0
983 if !exists("b:netrw_curdir")
984 let b:netrw_curdir= getcwd()
985 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200987
988 " switch on starpat to build the w:netrw_explore_list of files
989 if starpat == 1
990 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
992" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100994 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200995 catch /^Vim\%((\a\+)\)\=:E480/
996 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
997" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
998 return
999 endtry
1000 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1001 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1002
1003 elseif starpat == 2
1004 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001005" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1006" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001008 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 catch /^Vim\%((\a\+)\)\=:E480/
1010 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1011 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001012 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001013" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001014 if @* != keepregstar | sil! let @* = keepregstar | endif
1015 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001016 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 sil! let @/ = keepregslash
1018" call Dret("netrw#Explore : no files matched pattern")
1019 return
1020 endtry
1021 let s:netrw_curdir = b:netrw_curdir
1022 let w:netrw_explore_list = getqflist()
1023 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1024 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1025
1026 elseif starpat == 3
1027 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001028" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001029 let filepat= substitute(dirname,'^\*/','','')
1030 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001031" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1032" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001033 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1034 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1035
1036 elseif starpat == 4
1037 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001038" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001039 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1040 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1041 endif " switch on starpat to build w:netrw_explore_list
1042
1043 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001044" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1045" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001046
1047 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001048 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001049 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001050" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001051 if @* != keepregstar | sil! let @* = keepregstar | endif
1052 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001053 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001054 sil! let @/ = keepregslash
1055" call Dret("netrw#Explore : no files matched")
1056 return
1057 endif
1058 endif " if indx ... endif
1059
1060 " NetrwStatusLine support - for exploring support
1061 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001062" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001063
1064 " wrap the indx around, but issue a note
1065 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001066" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001067 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1068 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001069 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 endif
1071
1072 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001075" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001076
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 call netrw#LocalBrowseCheck(newdir)
1079 if !exists("w:netrw_liststyle")
1080 let w:netrw_liststyle= g:netrw_liststyle
1081 endif
1082 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001083 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001085 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 endif
1087 let w:netrw_explore_mtchcnt = indx + 1
1088 let w:netrw_explore_bufnr = bufnr("%")
1089 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001091" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001092
1093 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001094" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001095 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096 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 +02001097 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001098 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001099" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001100 if @* != keepregstar | sil! let @* = keepregstar | endif
1101 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001102 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 sil! let @/ = keepregslash
1104" call Dret("netrw#Explore : missing +path_extra")
1105 return
1106 endif
1107
1108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001109" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001110 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1111 sil! unlet w:netrw_treedict
1112 sil! unlet w:netrw_treetop
1113 endif
1114 let newdir= dirname
1115 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001116 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001117 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001118 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001119 endif
1120 endif
1121
1122 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001123" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1124" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001126" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001128 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 let s:explore_prvdir = b:netrw_curdir
1131 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001132 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if b:netrw_curdir !~ '/$'
1134 let dirlen= dirlen + 1
1135 endif
1136 let prvfname= ""
1137 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001138" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001139 if fname =~ '^'.b:netrw_curdir
1140 if s:explore_match == ""
1141 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1142 else
1143 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1144 endif
1145 elseif fname !~ '^/' && fname != prvfname
1146 if s:explore_match == ""
1147 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1148 else
1149 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1150 endif
1151 endif
1152 let prvfname= fname
1153 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001154" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001155 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1156 exe "2match netrwMarkFile /".s:explore_match."/"
1157 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001158 endif
1159 echo "<s-up>==Pexplore <s-down>==Nexplore"
1160 else
1161 2match none
1162 if exists("s:explore_match") | unlet s:explore_match | endif
1163 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001164" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001165 endif
1166
Bram Moolenaara6878372014-03-22 21:02:50 +01001167 " since Explore may be used to initialize netrw's browser,
1168 " there's no danger of a late FocusGained event on initialization.
1169 " Consequently, set s:netrw_events to 2.
1170 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001171 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001172" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001173 if @* != keepregstar | sil! let @* = keepregstar | endif
1174 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001175 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001176 sil! let @/ = keepregslash
1177" call Dret("netrw#Explore : @/<".@/.">")
1178endfun
1179
1180" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001181" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001182" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1183" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1184" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1185" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1186" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001187fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001188" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189 let curwin= winnr()
1190
Bram Moolenaara6878372014-03-22 21:02:50 +01001191 if a:0 > 0 && a:1 != ""
1192 " if a netrw window is already on the left-side of the tab
1193 " and a directory has been specified, explore with that
1194 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001195" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001196 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001197" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001198 exe "1wincmd w"
1199 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001200" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 exe "Explore ".fnameescape(a1)
1202 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001203 let s:lexplore_win= curwin
1204 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001205 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001206" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 unlet t:netrw_lexposn
1208 endif
1209" call Dret("netrw#Lexplore")
1210 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001211 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 exe curwin."wincmd w"
1213 else
1214 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001215" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
1217
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 else
1223 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001224" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227
1228 if lexwinnr > 0
1229 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001230" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 exe lexwinnr."wincmd w"
1232 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001233 let t:netrw_lexposn = winsaveview()
1234" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001235" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 close
1237 if lexwinnr < curwin
1238 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001239 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001240 if lexwinnr != curwin
1241 exe curwin."wincmd w"
1242 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001243 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001244" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245
1246 else
1247 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001248" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249 exe "1wincmd w"
1250 let keep_altv = g:netrw_altv
1251 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 if a:count != 0
1253 let netrw_winsize = g:netrw_winsize
1254 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001257" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001259" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001261" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001262 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264 elseif curfile =~ '^\a\{3,}://'
1265" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001266 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001268" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001269 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 endif
1271 if a:count != 0
1272 let g:netrw_winsize = netrw_winsize
1273 endif
1274 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001275 let g:netrw_altv = keep_altv
1276 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001277 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1278 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001279 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001280 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001281" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1282" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001283 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001284" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001285" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1286 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001287 unlet t:netrw_lexposn
1288 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001289 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290
1291 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001292 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293 if a:rightside
1294 let g:netrw_chgwin= 1
1295 else
1296 let g:netrw_chgwin= 2
1297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001298" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001299 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001300
Bram Moolenaar8d043172014-01-23 14:24:41 +01001301" call Dret("netrw#Lexplore")
1302endfun
1303
1304" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001305" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001306" supports :NetrwClean -- remove netrw from first directory on runtimepath
1307" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001308fun! netrw#Clean(sys)
1309" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001310
1311 if a:sys
1312 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1313 else
1314 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001316" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001317 let diddel= 0
1318 let diddir= ""
1319
1320 if choice == 1
1321 for dir in split(&rtp,',')
1322 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001323" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001324 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1325 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1326 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1327 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1328 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1329 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 +00001330 let diddir= dir
1331 let diddel= diddel + 1
1332 if !a:sys|break|endif
1333 endif
1334 endfor
1335 endif
1336
1337 echohl WarningMsg
1338 if diddel == 0
1339 echomsg "netrw is either not installed or not removable"
1340 elseif diddel == 1
1341 echomsg "removed one copy of netrw from <".diddir.">"
1342 else
1343 echomsg "removed ".diddel." copies of netrw"
1344 endif
1345 echohl None
1346
Bram Moolenaara6878372014-03-22 21:02:50 +01001347" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001348endfun
1349
Bram Moolenaar5c736222010-01-06 20:54:52 +01001350" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001351" netrw#MakeTgt: make a target out of the directory name provided {{{2
1352fun! netrw#MakeTgt(dname)
1353" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1354 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001355 let svpos = winsaveview()
1356" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001357 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1358" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001359 if s:netrwmftgt_islocal
1360 let netrwmftgt= simplify(a:dname)
1361 else
1362 let netrwmftgt= a:dname
1363 endif
1364 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1365 " re-selected target, so just clear it
1366 unlet s:netrwmftgt s:netrwmftgt_islocal
1367 else
1368 let s:netrwmftgt= netrwmftgt
1369 endif
1370 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001371 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001372 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001373" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1374 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001375" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001376endfun
1377
Bram Moolenaara6878372014-03-22 21:02:50 +01001378" ---------------------------------------------------------------------
1379" netrw#Obtain: {{{2
1380" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001381" islocal=0 obtain from remote source
1382" =1 obtain from local source
1383" fname : a filename or a list of filenames
1384" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001385fun! netrw#Obtain(islocal,fname,...)
1386" 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 +02001387 " NetrwStatusLine support - for obtaining support
1388
1389 if type(a:fname) == 1
1390 let fnamelist= [ a:fname ]
1391 elseif type(a:fname) == 3
1392 let fnamelist= a:fname
1393 else
1394 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 +01001395" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 return
1397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001398" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 if a:0 > 0
1400 let tgtdir= a:1
1401 else
1402 let tgtdir= getcwd()
1403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405
1406 if exists("b:netrw_islocal") && b:netrw_islocal
1407 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1410 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001411 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001416 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 if v:shell_error != 0
1418 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 +01001419" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 return
1421 endif
1422 endfor
1423 else
1424 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001425" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1426 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1427" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001428 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001429 if v:shell_error != 0
1430 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 +01001431" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 return
1433 endif
1434 endif
1435 elseif !exists("b:netrw_curdir")
1436 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1437 else
1438 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1439 endif
1440
1441 else
1442 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001443" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 if type(a:fname) == 1
1445 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1446 endif
1447 call s:NetrwMethod(b:netrw_curdir)
1448
1449 if b:netrw_method == 4
1450 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 if exists("g:netrw_port") && g:netrw_port != ""
1453 let useport= " ".g:netrw_scpport." ".g:netrw_port
1454 else
1455 let useport= ""
1456 endif
1457 if b:netrw_fname =~ '/'
1458 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1459 else
1460 let path= ""
1461 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001462 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463 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 +02001464
1465 elseif b:netrw_method == 2
1466 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001467" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001468 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001469 let tmpbufnr= bufnr("%")
1470 setl ff=unix
1471 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001472 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 endif
1475
1476 if exists("b:netrw_fname") && b:netrw_fname != ""
1477 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 endif
1480
1481 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485 for fname in fnamelist
1486 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001487" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 endfor
1489 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 endif
1494 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1495 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1496 let debugkeep= &debug
1497 setl debug=msg
1498 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1499 let &debug= debugkeep
1500 endif
1501
1502 elseif b:netrw_method == 3
1503 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001504" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001506 let tmpbufnr= bufnr("%")
1507 setl ff=unix
1508
1509 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001511" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 endif
1516
1517 if exists("g:netrw_uid") && g:netrw_uid != ""
1518 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
1529 endif
1530
1531 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 endif
1535
1536 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540
1541 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545
1546 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endif
1550 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001551 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554
1555 " perform ftp:
1556 " -i : turns off interactive prompting from ftp
1557 " -n unix : DON'T use <.netrc>, even though it exists
1558 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001559 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1560 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001561 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1563 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001564" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001565 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 endif
1568 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001569
1570 elseif b:netrw_method == 9
1571 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001572" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001573 if a:fname =~ '/'
1574 let localfile= substitute(a:fname,'^.*/','','')
1575 else
1576 let localfile= a:fname
1577 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001578 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 +02001579
Bram Moolenaarff034192013-04-24 18:51:19 +02001580 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 " probably a badly formed url; protocol not recognized
1582" call Dret("netrw#Obtain : unsupported method")
1583 return
1584
1585 else
1586 " protocol recognized but not supported for Obtain (yet?)
1587 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001588 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001589 endif
1590" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001591 return
1592 endif
1593
1594 " restore status line
1595 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001596 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001597 endif
1598
1599 endif
1600
1601 " cleanup
1602 if exists("tmpbufnr")
1603 if bufnr("%") != tmpbufnr
1604 exe tmpbufnr."bw!"
1605 else
1606 q!
1607 endif
1608 endif
1609
Bram Moolenaara6878372014-03-22 21:02:50 +01001610" call Dret("netrw#Obtain")
1611endfun
1612
1613" ---------------------------------------------------------------------
1614" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1615fun! netrw#Nread(mode,fname)
1616" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001617 let svpos= winsaveview()
1618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001619 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1621 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001622
1623 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1624 if exists("w:netrw_bannercnt")
1625 " start with cursor just after the banner
1626 exe w:netrw_bannercnt
1627 endif
1628 endif
1629" call Dret("netrw#Nread")
1630endfun
1631
1632" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001633" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1634" Options get restored by s:NetrwOptionsRestore()
1635"
1636" Option handling:
1637" * save user's options (s:NetrwOptionsSave)
1638" * set netrw-safe options (s:NetrwOptionsSafe)
1639" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1640" * restore user's options (s:netrwOPtionsRestore)
1641" - restore a user option when != safe option (s:NetrwRestoreSetting)
1642" vt: (variable type) normally its either "w:" or "s:"
1643fun! s:NetrwOptionsSave(vt)
1644" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1645" 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 +02001646" 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>"))
1647" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001648
1649 if !exists("{a:vt}netrw_optionsave")
1650 let {a:vt}netrw_optionsave= 1
1651 else
1652" call Dret("s:NetrwOptionsSave : options already saved")
1653 return
1654 endif
1655" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1656
1657 " Save current settings and current directory
1658" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1659 let s:yykeep = @@
1660 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1661 let {a:vt}netrw_aikeep = &l:ai
1662 let {a:vt}netrw_awkeep = &l:aw
1663 let {a:vt}netrw_bhkeep = &l:bh
1664 let {a:vt}netrw_blkeep = &l:bl
1665 let {a:vt}netrw_btkeep = &l:bt
1666 let {a:vt}netrw_bombkeep = &l:bomb
1667 let {a:vt}netrw_cedit = &cedit
1668 let {a:vt}netrw_cikeep = &l:ci
1669 let {a:vt}netrw_cinkeep = &l:cin
1670 let {a:vt}netrw_cinokeep = &l:cino
1671 let {a:vt}netrw_comkeep = &l:com
1672 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001673 let {a:vt}netrw_cuckeep = &l:cuc
1674 let {a:vt}netrw_culkeep = &l:cul
1675" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001676 let {a:vt}netrw_diffkeep = &l:diff
1677 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1679 let {a:vt}netrw_ffkeep = &l:ff
1680 endif
1681 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1682 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001683 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_hidkeep = &l:hidden
1685 let {a:vt}netrw_imkeep = &l:im
1686 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001687 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001688 let {a:vt}netrw_lskeep = &l:ls
1689 let {a:vt}netrw_makeep = &l:ma
1690 let {a:vt}netrw_magickeep = &l:magic
1691 let {a:vt}netrw_modkeep = &l:mod
1692 let {a:vt}netrw_nukeep = &l:nu
1693 let {a:vt}netrw_rnukeep = &l:rnu
1694 let {a:vt}netrw_repkeep = &l:report
1695 let {a:vt}netrw_rokeep = &l:ro
1696 let {a:vt}netrw_selkeep = &l:sel
1697 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001698 if !g:netrw_use_noswf
1699 let {a:vt}netrw_swfkeep = &l:swf
1700 endif
1701 let {a:vt}netrw_tskeep = &l:ts
1702 let {a:vt}netrw_twkeep = &l:tw " textwidth
1703 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1704 let {a:vt}netrw_wrapkeep = &l:wrap
1705 let {a:vt}netrw_writekeep = &l:write
1706
1707 " save a few selected netrw-related variables
1708" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1709 if g:netrw_keepdir
1710 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001711" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001712 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001713 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001714 sil! let {a:vt}netrw_starkeep = @*
1715 sil! let {a:vt}netrw_pluskeep = @+
1716 endif
1717 sil! let {a:vt}netrw_slashkeep= @/
1718
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720" 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>"))
1721" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1722endfun
1723
1724" ---------------------------------------------------------------------
1725" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1726" Use s:NetrwSaveOptions() to save user settings
1727" Use s:NetrwOptionsRestore() to restore user settings
1728fun! s:NetrwOptionsSafe(islocal)
1729" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1730" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1731" 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>"))
1732 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1733 call s:NetrwSetSafeSetting("&l:ai",0)
1734 call s:NetrwSetSafeSetting("&l:aw",0)
1735 call s:NetrwSetSafeSetting("&l:bl",0)
1736 call s:NetrwSetSafeSetting("&l:bomb",0)
1737 if a:islocal
1738 call s:NetrwSetSafeSetting("&l:bt","nofile")
1739 else
1740 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1741 endif
1742 call s:NetrwSetSafeSetting("&l:ci",0)
1743 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001744 if g:netrw_fastbrowse > a:islocal
1745 call s:NetrwSetSafeSetting("&l:bh","hide")
1746 else
1747 call s:NetrwSetSafeSetting("&l:bh","delete")
1748 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001749 call s:NetrwSetSafeSetting("&l:cino","")
1750 call s:NetrwSetSafeSetting("&l:com","")
1751 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1752 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1753 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001754 if &go =~ 'a' | set go-=a | endif
1755 if &go =~ 'A' | set go-=A | endif
1756 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001757 call s:NetrwSetSafeSetting("&l:hid",0)
1758 call s:NetrwSetSafeSetting("&l:im",0)
1759 setl isk+=@ isk+=* isk+=/
1760 call s:NetrwSetSafeSetting("&l:magic",1)
1761 if g:netrw_use_noswf
1762 call s:NetrwSetSafeSetting("swf",0)
1763 endif
1764 call s:NetrwSetSafeSetting("&l:report",10000)
1765 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1766 call s:NetrwSetSafeSetting("&l:spell",0)
1767 call s:NetrwSetSafeSetting("&l:tw",0)
1768 call s:NetrwSetSafeSetting("&l:wig","")
1769 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001770
1771 " set up cuc and cul based on g:netrw_cursor and listing style
1772 " COMBAK -- cuc cul related
1773 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001774
1775 " allow the user to override safe options
1776" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1777 if &ft == "netrw"
1778" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1779 keepalt NetrwKeepj doau FileType netrw
1780 endif
1781
1782" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1783" 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>"))
1784" call Dret("s:NetrwOptionsSafe")
1785endfun
1786
1787" ---------------------------------------------------------------------
1788" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1789fun! s:NetrwOptionsRestore(vt)
1790" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001791" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001792" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001793 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001794" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001795
1796 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1797 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001798" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001799 filetype detect
1800" 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>"))
1801 else
1802 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001803 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001804" 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 +02001805" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001806 return
1807 endif
1808 unlet {a:vt}netrw_optionsave
1809
1810 if exists("+acd")
1811 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001812" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001813 let curdir = getcwd()
1814 let &l:acd = {a:vt}netrw_acdkeep
1815 unlet {a:vt}netrw_acdkeep
1816 if &l:acd
1817 call s:NetrwLcd(curdir)
1818 endif
1819 endif
1820 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001821" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001822 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1823 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1824 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1825 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1826 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001827" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001828 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1829 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1830 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1831 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1832 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1835 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1836 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1837 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1838 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001839 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001840" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1841 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1842 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001843 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001844 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1845" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1847 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1848" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1850" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1851 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1852 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001853 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001854 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1855 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1856" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1858 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1859 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1860 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1861" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1864 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1865 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001867" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 call s:NetrwRestoreSetting("s:yykeep","@@")
1869 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1870 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1871 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1872 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1873
Bram Moolenaara6878372014-03-22 21:02:50 +01001874 if exists("{a:vt}netrw_swfkeep")
1875 if &directory == ""
1876 " user hasn't specified a swapfile directory;
1877 " netrw will temporarily set the swapfile directory
1878 " to the current directory as returned by getcwd().
1879 let &l:directory= getcwd()
1880 sil! let &l:swf = {a:vt}netrw_swfkeep
1881 setl directory=
1882 unlet {a:vt}netrw_swfkeep
1883 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001884 if !g:netrw_use_noswf
1885 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1886 sil! let &l:swf= {a:vt}netrw_swfkeep
1887 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001888 unlet {a:vt}netrw_swfkeep
1889 endif
1890 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001891 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001892 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1893 if exists("{a:vt}netrw_dirkeep")
1894 call s:NetrwLcd(dirkeep)
1895 unlet {a:vt}netrw_dirkeep
1896 endif
1897 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001898 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001899" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001900 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1901 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001902 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001903 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001904
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001905" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1906" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1907" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1908" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1909" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001910 " Moved the filetype detect here from NetrwGetFile() because remote files
1911 " were having their filetype detect-generated settings overwritten by
1912 " NetrwOptionRestore.
1913 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001914" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1915 filetype detect
1916" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001917 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001918" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001919" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001920" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001921endfun
1922
1923" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001924" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1925" but only when the options' value and the safe setting differ
1926" Doing this means that netrw will not come up as having changed a
1927" setting last when it really didn't actually change it.
1928"
1929" Called from s:NetrwOptionsSafe
1930" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1931fun! s:NetrwSetSafeSetting(setting,safesetting)
1932" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001933
Bram Moolenaar85850f32019-07-19 22:05:51 +02001934 if a:setting =~ '^&'
1935" call Decho("fyi: a:setting starts with &")
1936 exe "let settingval= ".a:setting
1937" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001938
Bram Moolenaar85850f32019-07-19 22:05:51 +02001939 if settingval != a:safesetting
1940" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1941 if type(a:safesetting) == 0
1942 exe "let ".a:setting."=".a:safesetting
1943 elseif type(a:safesetting) == 1
1944 exe "let ".a:setting."= '".a:safesetting."'"
1945 else
1946 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1947 endif
1948 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001949 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001950
Bram Moolenaar85850f32019-07-19 22:05:51 +02001951" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001952endfun
1953
1954" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001955" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1956" but only if the setting value differs from the associated keepvar.
1957" Doing this means that netrw will not come up as having changed a
1958" setting last when it really didn't actually change it.
1959"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001960" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961" keepvars are set up by s:NetrwOptionsSave
1962fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001963""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001964
Bram Moolenaar85850f32019-07-19 22:05:51 +02001965 " typically called from s:NetrwOptionsRestore
1966 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1967 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001968 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969 if exists(a:keepvar)
1970 exe "let keepvarval= ".a:keepvar
1971 exe "let setting= ".a:setting
1972
1973"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1974"" call Decho("fyi: keepvarval=".keepvarval)
1975"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1976
1977 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001978"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001979 if type(a:setting) == 0
1980 exe "let ".a:setting."= ".keepvarval
1981 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001982 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001983 else
1984 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1985 endif
1986 endif
1987
1988 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001989 endif
1990
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001992endfun
1993
1994" ---------------------------------------------------------------------
1995" NetrwStatusLine: {{{2
1996fun! NetrwStatusLine()
1997
1998" vvv NetrwStatusLine() debugging vvv
1999" let g:stlmsg=""
2000" if !exists("w:netrw_explore_bufnr")
2001" let g:stlmsg="!X<explore_bufnr>"
2002" elseif w:netrw_explore_bufnr != bufnr("%")
2003" let g:stlmsg="explore_bufnr!=".bufnr("%")
2004" endif
2005" if !exists("w:netrw_explore_line")
2006" let g:stlmsg=" !X<explore_line>"
2007" elseif w:netrw_explore_line != line(".")
2008" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2009" endif
2010" if !exists("w:netrw_explore_list")
2011" let g:stlmsg=" !X<explore_list>"
2012" endif
2013" ^^^ NetrwStatusLine() debugging ^^^
2014
2015 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")
2016 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002017 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002018 let &laststatus = s:netrw_users_ls
2019 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2020 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2021 return ""
2022 else
2023 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2024 endif
2025endfun
2026
Bram Moolenaar85850f32019-07-19 22:05:51 +02002027" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002028" Netrw Transfer Functions: {{{1
2029" ===============================
2030
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002032" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002033" mode: =0 read remote file and insert before current line
2034" =1 read remote file and insert after current line
2035" =2 replace with remote file
2036" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002037fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002038" 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 +00002039
Bram Moolenaar5c736222010-01-06 20:54:52 +01002040 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002041 call s:NetrwOptionsSave("w:")
2042 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002043 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002044 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2045 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2046 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002047" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002048
Bram Moolenaar5c736222010-01-06 20:54:52 +01002049 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 elseif a:mode == 2 " replace with remote file
2055 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002056 elseif a:mode == 3 " skip read of file (leave as temporary)
2057 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 else
2059 exe a:mode
2060 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002061 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002063" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064
Bram Moolenaar5c736222010-01-06 20:54:52 +01002065 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002066 let tmpfile= s:GetTempfile("")
2067 if tmpfile == ""
2068" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002069 return
2070 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002073
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 " attempt to repeat with previous host-file-etc
2075 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002076" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 let choice = b:netrw_lastfile
2078 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 else
2081 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002083
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002084 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002085 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002086 echomsg 'NetRead Usage:'
2087 echomsg ':Nread machine:path uses rcp'
2088 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2089 echomsg ':Nread "machine id password path" uses ftp'
2090 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2091 echomsg ':Nread fetch://machine/path uses fetch'
2092 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2093 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002094 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002095 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002096 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2097 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2098 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2099 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002100 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002102
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002104 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002105" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002108 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 else
2110 " case "... ... ..."
2111 let choice = strpart(choice,1,strlen(choice)-1)
2112 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 let wholechoice = wholechoice . " " . choice
2116 let ichoice = ichoice + 1
2117 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002118 if !exists("g:netrw_quiet")
2119 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2120 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002121" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002122 return
2123 endif
2124 let choice= a:{ichoice}
2125 endwhile
2126 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2127 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 endif
2129 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002132 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002133
Bram Moolenaar5c736222010-01-06 20:54:52 +01002134 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002135 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002136 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002137" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002138 return
2139 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002140 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002141
Bram Moolenaar8d043172014-01-23 14:24:41 +01002142 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143" 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 +02002144 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002145" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002147" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002148 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002150
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002152 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002153 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002154 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2155 echo "(netrw) Processing your read request..."
2156 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002157
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002159 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002161" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002162 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002164 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 " ER: the tmpfile is full path: rcp sees C:\... as host C
2166 if s:netrw_has_nt_rcp == 1
2167 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2168 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2169 else
2170 " Any way needed it machine contains a '.'
2171 let uid_machine = g:netrw_machine .'.'. $USERNAME
2172 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2175 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2176 else
2177 let uid_machine = g:netrw_machine
2178 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002180 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 +00002181 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002183
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002184 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002185 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002187" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002188 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002189 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002190 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002191 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002194 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002197 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002198 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 endif
2205 " 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 +00002206 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002207 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002208 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002209 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002210 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002211 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002212 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002213 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002214 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2215 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002216 q!
2217 endif
2218 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002219 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002221
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002223 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2225 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002226" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002227 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002228 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002229 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002230 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002232 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002235 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002236" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002238
Bram Moolenaar97d62492012-11-15 21:28:22 +01002239 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002240 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002252
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002257 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002261 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002263
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 " perform ftp:
2265 " -i : turns off interactive prompting from ftp
2266 " -n unix : DON'T use <.netrc>, even though it exists
2267 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002268 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002269 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002270 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2271 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002272" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002273 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002274 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002275 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002278 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002280
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002282 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002284" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002286 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 else
2288 let useport= ""
2289 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002290 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2291 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002292 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002293 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2294 else
2295 let tmpfile_get = tmpfile
2296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002297 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 +00002298 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002299 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002300
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002301 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002302 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002303 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002304" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002306 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002307 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002308 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002309" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002310 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002312
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002313 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2314 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002315" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002316 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317 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 +00002318 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002319 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 +00002320 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002321 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002322
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002324 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002326 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2327 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2329" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2330 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 +00002331 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002332" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002333 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002334 endif
2335 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002337 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002338
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002340 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002341 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002343
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 if !executable(g:netrw_dav_cmd)
2345 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2346" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2347 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002348 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350 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 +01002351 else
2352 " Construct execution string (four lines) which will be passed through filter
2353 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2354 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002355 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002357 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002358 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002359 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002361 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002363 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2365 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002366
Bram Moolenaar5c736222010-01-06 20:54:52 +01002367 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002368 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002370 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002371 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002372 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002373 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002375 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002377 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002379 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 +00002380 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002384 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002386 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002387" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002389 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002390 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002391 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002392" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002393 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002395 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 let netrw_option= "http"
2397 else
2398 let netrw_option= "ftp"
2399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002400" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002401
Bram Moolenaar446cb832008-06-24 21:56:24 +00002402 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002403 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405 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 +00002406 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002407
Bram Moolenaar446cb832008-06-24 21:56:24 +00002408 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002409 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002411 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002414 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002415 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002416" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2417 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 +00002418 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002420
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002422 " NetRead: (file) NetRead Method #10 {{{3
2423 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002424" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2425 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002426 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2427 let b:netrw_lastfile = choice
2428
2429 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002430 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002431 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002432 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 endif
2434 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002435
Bram Moolenaar5c736222010-01-06 20:54:52 +01002436 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002438" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 unlet b:netrw_fname
2441 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002442 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 +01002443" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002444 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002446 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002447
Bram Moolenaar9964e462007-05-05 17:54:07 +00002448" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449endfun
2450
2451" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002452" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002453fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002455
Bram Moolenaar5c736222010-01-06 20:54:52 +01002456 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002458 call s:NetrwOptionsSave("w:")
2459 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002462 let tmpfile= s:GetTempfile("")
2463 if tmpfile == ""
2464" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002465 return
2466 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002467
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002468 if a:0 == 0
2469 let ichoice = 0
2470 else
2471 let ichoice = 1
2472 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002473
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002475" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002476 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002477 " For binary writes, always write entire file.
2478 " (line numbers don't really make sense for that).
2479 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002481 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 elseif g:netrw_cygwin
2483 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002484 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" 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 +01002486 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002487 else
2488 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489" 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 +01002490 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002491 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002492
Bram Moolenaar9964e462007-05-05 17:54:07 +00002493 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002494 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495 " on the temporary file's name. Deletion of the temporary file during
2496 " cleanup then causes an error message.
2497 0file!
2498 endif
2499
Bram Moolenaar5c736222010-01-06 20:54:52 +01002500 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002501 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002502
Bram Moolenaar9964e462007-05-05 17:54:07 +00002503 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 " attempt to repeat with previous host-file-etc
2505 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002506" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 let choice = b:netrw_lastfile
2508 let ichoice= ichoice + 1
2509 else
2510 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002511
Bram Moolenaar8d043172014-01-23 14:24:41 +01002512 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002514 echomsg 'NetWrite Usage:"'
2515 echomsg ':Nwrite machine:path uses rcp'
2516 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2517 echomsg ':Nwrite "machine id password path" uses ftp'
2518 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2519 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2520 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2521 echomsg ':Nwrite rcp://machine/path uses rcp'
2522 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2523 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2524 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002525 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002526 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002527
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002528 elseif match(choice,"^\"") != -1
2529 if match(choice,"\"$") != -1
2530 " case "..."
2531 let choice=strpart(choice,1,strlen(choice)-2)
2532 else
2533 " case "... ... ..."
2534 let choice = strpart(choice,1,strlen(choice)-1)
2535 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002536
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 while match(choice,"\"$") == -1
2538 let wholechoice= wholechoice . " " . choice
2539 let ichoice = ichoice + 1
2540 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002541 if !exists("g:netrw_quiet")
2542 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2543 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002544" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 return
2546 endif
2547 let choice= a:{ichoice}
2548 endwhile
2549 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2550 endif
2551 endif
2552 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002554" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002555
Bram Moolenaar9964e462007-05-05 17:54:07 +00002556 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002557 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002558 if !exists("b:netrw_method") || b:netrw_method < 0
2559" call Dfunc("netrw#NetWrite : unsupported method")
2560 return
2561 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002562
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002563 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002565 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002566 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2567 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002568" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002569 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002572 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002573 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002574" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 if s:netrw_has_nt_rcp == 1
2576 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2577 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2578 else
2579 let uid_machine = g:netrw_machine .'.'. $USERNAME
2580 endif
2581 else
2582 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2583 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2584 else
2585 let uid_machine = g:netrw_machine
2586 endif
2587 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002588 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 +00002589 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002590
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002591 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002592 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002593 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002595 let netrw_fname = b:netrw_fname
2596
2597 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2598 let bhkeep = &l:bh
2599 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002600 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002602
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002604 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002605 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002607 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002610 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614 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 +00002615 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2617 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 endif
2619 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2620 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002621 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002622 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002623 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002624 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002626
2627 " remove enew buffer (quietly)
2628 let filtbuf= bufnr("%")
2629 exe curbuf."b!"
2630 let &l:bh = bhkeep
2631 exe filtbuf."bw!"
2632
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002634
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002635 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002636 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002637 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002639" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640 let netrw_fname = b:netrw_fname
2641 let bhkeep = &l:bh
2642
2643 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2644 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002645 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002647 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002650 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002656 if exists("g:netrw_uid") && g:netrw_uid != ""
2657 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002668 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002671 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 " save choice/id/password for future use
2678 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002679
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002680 " perform ftp:
2681 " -i : turns off interactive prompting from ftp
2682 " -n unix : DON'T use <.netrc>, even though it exists
2683 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002684 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002685 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2687 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002688 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002689 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002690 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 let mod=1
2692 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002693
2694 " remove enew buffer (quietly)
2695 let filtbuf= bufnr("%")
2696 exe curbuf."b!"
2697 let &l:bh= bhkeep
2698 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002699
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002701 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002702 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002703" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002705 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 else
2707 let useport= ""
2708 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709 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 +00002710 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002711
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002713 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002716 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2717 if executable(curl)
2718 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719 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 +01002720 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002721 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002722 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002723
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002724 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002725 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002726 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002728
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002729 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002730 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2731 let bhkeep = &l:bh
2732
2733 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2734 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002735 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002736 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002737
Bram Moolenaarff034192013-04-24 18:51:19 +02002738 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002739 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002740 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002742 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002743 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002744 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002746 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002748
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002750 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002752
2753 " remove enew buffer (quietly)
2754 let filtbuf= bufnr("%")
2755 exe curbuf."b!"
2756 let &l:bh = bhkeep
2757 exe filtbuf."bw!"
2758
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002759 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002760
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002761 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002762 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002763 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002764" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002765 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 +00002766 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002767
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002768 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002769 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002770 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002771" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2774 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2775 else
2776 let uid_machine = g:netrw_machine
2777 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002778
2779 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2780 let bhkeep = &l:bh
2781 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002782 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002783 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002784
Bram Moolenaarff034192013-04-24 18:51:19 +02002785 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002788 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790 let filtbuf= bufnr("%")
2791 exe curbuf."b!"
2792 let &l:bh = bhkeep
2793 exe filtbuf."bw!"
2794 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002795
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002796 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002797 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002798 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002799 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002800 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002802 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaar5c736222010-01-06 20:54:52 +01002804 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002805" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002807" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002808 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002810 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002811
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002812 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002814 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002816 elseif !exists("leavemod")
2817 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002819 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" 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 +00002821 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002822
Bram Moolenaar9964e462007-05-05 17:54:07 +00002823" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002824endfun
2825
2826" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002827" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828" uses NetRead to get a copy of the file into a temporarily file,
2829" then sources that file,
2830" then removes that file.
2831fun! netrw#NetSource(...)
2832" call Dfunc("netrw#NetSource() a:0=".a:0)
2833 if a:0 > 0 && a:1 == '?'
2834 " give help
2835 echomsg 'NetSource Usage:'
2836 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2837 echomsg ':Nsource fetch://machine/path uses fetch'
2838 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002839 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002840 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2841 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2842 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2843 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2844 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002845 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002847 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002852 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002854 if delete(s:netrw_tmpfile)
2855 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2856 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002857 unlet s:netrw_tmpfile
2858 else
2859 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2860 endif
2861 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002862 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 endif
2864" call Dret("netrw#NetSource")
2865endfun
2866
Bram Moolenaar8d043172014-01-23 14:24:41 +01002867" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002868" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2869" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002870fun! netrw#SetTreetop(iscmd,...)
2871" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2872" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002873
Bram Moolenaar85850f32019-07-19 22:05:51 +02002874 " iscmd==0: netrw#SetTreetop called using gn mapping
2875 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2876" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 " clear out the current tree
2878 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002879" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002880 let inittreetop= w:netrw_treetop
2881 unlet w:netrw_treetop
2882 endif
2883 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 unlet w:netrw_treedict
2886 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002887" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002888
Bram Moolenaar85850f32019-07-19 22:05:51 +02002889 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002890 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002891" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002892 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893 if isdirectory(s:NetrwFile(a:1))
2894" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = a:1
2896 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = b:netrw_curdir."/".a:1
2899 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002900" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002901 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 " normally the cursor is left in the message window.
2903 " However, here this results in the directory being listed in the message window, which is not wanted.
2904 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002905 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002907 let treedir = "."
2908 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 endif
2910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002912
2913 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914 let islocal= expand("%") !~ '^\a\{3,}://'
2915" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916
2917 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002918 if islocal
2919 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2920 else
2921 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2922 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002923
Bram Moolenaara6878372014-03-22 21:02:50 +01002924" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002925endfun
2926
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002928" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002929" readcmd == %r : replace buffer with newly read file
2930" == 0r : read file at top of buffer
2931" == r : read file after current line
2932" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933fun! s:NetrwGetFile(readcmd, tfile, method)
2934" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935
2936 " readcmd=='t': simply do nothing
2937 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002938" 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 +01002939" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002940 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002941 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002942
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943 " get name of remote filename (ie. url and all)
2944 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002945" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002946
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947 if exists("*NetReadFixup")
2948 " for the use of NetReadFixup (not otherwise used internally)
2949 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002950 endif
2951
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 if a:readcmd[0] == '%'
2953 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002954" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955
2956 " rename the current buffer to the temp file (ie. tfile)
2957 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002958 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 else
2960 let tfile= a:tfile
2961 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002962 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963
2964 " edit temporary file (ie. read the temporary file in)
2965 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 call zip#Browse(tfile)
2968 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002971 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 call tar#Browse(tfile)
2980 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002983 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002985 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002986 endif
2987
2988 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002989 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002990
Bram Moolenaar71badf92023-04-22 22:40:14 +01002991 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002992 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002993 " Note that isk must not include a "/" for scripts.vim
2994 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002995" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2996" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002997" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002998" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2999 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003000 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003001 filetype detect
3002" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003003 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003004" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003005 let line1 = 1
3006 let line2 = line("$")
3007
Bram Moolenaar8d043172014-01-23 14:24:41 +01003008 elseif !&ma
3009 " 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 +01003010 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003012 return
3013
Bram Moolenaar9964e462007-05-05 17:54:07 +00003014 elseif s:FileReadable(a:tfile)
3015 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 let curline = line(".")
3018 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003020 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003021 let line1= curline + 1
3022 let line2= line("$") - lastline + 1
3023
3024 else
3025 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003026" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3027" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003028 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003029" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003030 return
3031 endif
3032
3033 " User-provided (ie. optional) fix-it-up command
3034 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003035" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003036 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003037" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003039 endif
3040
Bram Moolenaaradc21822011-04-01 18:03:16 +02003041 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003042 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003043 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003044 endif
3045
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" 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 +00003047
3048 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003049" redraw!
3050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003051" 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 +00003052" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003053endfun
3054
Bram Moolenaar9964e462007-05-05 17:54:07 +00003055" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003056" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003057" Input:
3058" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3059" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003060" b:netrw_method= 1: rcp
3061" 2: ftp + <.netrc>
3062" 3: ftp + machine, id, password, and [path]filename
3063" 4: scp
3064" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003066" 7: rsync
3067" 8: fetch
3068" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003069" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003070" g:netrw_machine= hostname
3071" b:netrw_fname = filename
3072" g:netrw_port = optional port number (for ftp)
3073" g:netrw_choice = copy of input url (choice)
3074fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003075" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003076
Bram Moolenaar251e1912011-06-19 05:09:16 +02003077 " sanity check: choice should have at least three slashes in it
3078 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3079 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3080 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003081" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003082 return
3083 endif
3084
Bram Moolenaar5c736222010-01-06 20:54:52 +01003085 " record current g:netrw_machine, if any
3086 " curmachine used if protocol == ftp and no .netrc
3087 if exists("g:netrw_machine")
3088 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003089" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003090 else
3091 let curmachine= "N O T A HOST"
3092 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003093 if exists("g:netrw_port")
3094 let netrw_port= g:netrw_port
3095 endif
3096
3097 " insure that netrw_ftp_cmd starts off every method determination
3098 " with the current g:netrw_ftp_cmd
3099 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003100
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003101 " initialization
3102 let b:netrw_method = 0
3103 let g:netrw_machine = ""
3104 let b:netrw_fname = ""
3105 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003106 let g:netrw_choice = a:choice
3107
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003109 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003110 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3111 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003112 " rcpurm : rcp://[user@]host/filename Use rcp
3113 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003115 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003116 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 " rsyncurm : rsync://host[:port]/path Use rsync
3118 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3119 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003120 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3122 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003123 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3124 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003126 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003128 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003130 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003132 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003136 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003139 let b:netrw_method = 1
3140 let userid = substitute(a:choice,rcpurm,'\1',"")
3141 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3142 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 if userid != ""
3144 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003146
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003149" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003150 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003151 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3152 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3153 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaar15146672011-10-20 22:22:38 +02003155 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 let b:netrw_method = 5
3159 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3160 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003161 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaaradc21822011-04-01 18:03:16 +02003163 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003167 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003168 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3169 else
3170 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3171 endif
3172 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003173
Bram Moolenaaradc21822011-04-01 18:03:16 +02003174 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003176" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 let b:netrw_method = 7
3178 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3179 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003180
Bram Moolenaaradc21822011-04-01 18:03:16 +02003181 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003183" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003184 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3186 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3187 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003188" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003189 if userid != ""
3190 let g:netrw_uid= userid
3191 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003192
Bram Moolenaaradc21822011-04-01 18:03:16 +02003193 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003194 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003195 call NetUserPass("ftp:".g:netrw_machine)
3196 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003197 " if there's a change in hostname, require password re-entry
3198 unlet s:netrw_passwd
3199 endif
3200 if exists("netrw_port")
3201 unlet netrw_port
3202 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003203 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003204
Bram Moolenaar446cb832008-06-24 21:56:24 +00003205 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003206 let b:netrw_method = 3
3207 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208 let host= substitute(g:netrw_machine,'\..*$','','')
3209 if exists("s:netrw_hup[host]")
3210 call NetUserPass("ftp:".host)
3211
Nir Lichtman1e34b952024-05-08 19:19:34 +02003212 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003213" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3214" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003215 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003216 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003218 endif
3219 let b:netrw_method= 2
3220 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003222 let b:netrw_method= 2
3223 else
3224 if !exists("g:netrw_uid") || g:netrw_uid == ""
3225 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003226 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003228 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003229 endif
3230 let b:netrw_method= 3
3231 endif
3232 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003233
Bram Moolenaaradc21822011-04-01 18:03:16 +02003234 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003236" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 let b:netrw_method = 8
3238 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3239 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3240 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3241 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003242
Bram Moolenaaradc21822011-04-01 18:03:16 +02003243 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003244 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003245" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3248 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003249 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003251 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003252
Bram Moolenaaradc21822011-04-01 18:03:16 +02003253 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003255" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003256 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 let b:netrw_method = 3
3258 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3259 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaar9964e462007-05-05 17:54:07 +00003261 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_method = 2
3263 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3264 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3265 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003266
Bram Moolenaaradc21822011-04-01 18:03:16 +02003267 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003268 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003269" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 let b:netrw_method = 9
3271 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3272 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003273
Bram Moolenaaradc21822011-04-01 18:03:16 +02003274 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003275 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003276" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003277 let b:netrw_method = 1
3278 let userid = substitute(a:choice,rcphf,'\2',"")
3279 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3280 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3282" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3283" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3284" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003285 if userid != ""
3286 let g:netrw_uid= userid
3287 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003288
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003289 " Method#10: file://user@hostname/...path-to-file {{{3
3290 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003291" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003292 let b:netrw_method = 10
3293 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003294" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003295
Bram Moolenaaradc21822011-04-01 18:03:16 +02003296 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003297 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003298 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003299 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003300 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003301 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003303 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003304
Bram Moolenaar81695252004-12-29 20:58:21 +00003305 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003306 " remove any leading [:#] from port number
3307 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3308 elseif exists("netrw_port")
3309 " retain port number as implicit for subsequent ftp operations
3310 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003311 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003312
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003313" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3314" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3315" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3316" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003317" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003319" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003320" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003324" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326
Bram Moolenaar9964e462007-05-05 17:54:07 +00003327" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003328" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003329" Usage: :call NetUserPass() -- will prompt for userid and password
3330" :call NetUserPass("uid") -- will prompt for password
3331" :call NetUserPass("uid","password") -- sets global userid and password
3332" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3333" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334fun! NetUserPass(...)
3335
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003336" call Dfunc("NetUserPass() a:0=".a:0)
3337
3338 if !exists('s:netrw_hup')
3339 let s:netrw_hup= {}
3340 endif
3341
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003343 " case: no input arguments
3344
3345 " change host and username if not previously entered; get new password
3346 if !exists("g:netrw_machine")
3347 let g:netrw_machine= input('Enter hostname: ')
3348 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003350 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 let g:netrw_uid= input('Enter username: ')
3352 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003353 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003354 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355
3356 " set up hup database
3357 let host = substitute(g:netrw_machine,'\..*$','','')
3358 if !exists('s:netrw_hup[host]')
3359 let s:netrw_hup[host]= {}
3360 endif
3361 let s:netrw_hup[host].uid = g:netrw_uid
3362 let s:netrw_hup[host].passwd = s:netrw_passwd
3363
3364 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003365 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003366
3367 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003368 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003369 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003370" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003371 let host = substitute(a:1,'^ftp:','','')
3372 let host = substitute(host,'\..*','','')
3373 if exists("s:netrw_hup[host]")
3374 let g:netrw_uid = s:netrw_hup[host].uid
3375 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003376" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3377" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003378 else
3379 let g:netrw_uid = input("Enter UserId: ")
3380 let s:netrw_passwd = inputsecret("Enter Password: ")
3381 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003382
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003383 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003385" 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 +02003386 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003387 if g:netrw_machine =~ '[0-9.]\+'
3388 let host= g:netrw_machine
3389 else
3390 let host= substitute(g:netrw_machine,'\..*$','','')
3391 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003392 else
3393 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003394 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003395 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003396" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397 if exists("g:netrw_passwd")
3398 " ask for password if one not previously entered
3399 let s:netrw_passwd= g:netrw_passwd
3400 else
3401 let s:netrw_passwd = inputsecret("Enter Password: ")
3402 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003403 endif
3404
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003405" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406 if exists("host")
3407 if !exists('s:netrw_hup[host]')
3408 let s:netrw_hup[host]= {}
3409 endif
3410 let s:netrw_hup[host].uid = g:netrw_uid
3411 let s:netrw_hup[host].passwd = s:netrw_passwd
3412 endif
3413
3414 elseif a:0 == 2
3415 let g:netrw_uid = a:1
3416 let s:netrw_passwd = a:2
3417
3418 elseif a:0 == 3
3419 " enter hostname, user-id, and password into the hup dictionary
3420 let host = substitute(a:1,'^\a\+:','','')
3421 let host = substitute(host,'\..*$','','')
3422 if !exists('s:netrw_hup[host]')
3423 let s:netrw_hup[host]= {}
3424 endif
3425 let s:netrw_hup[host].uid = a:2
3426 let s:netrw_hup[host].passwd = a:3
3427 let g:netrw_uid = s:netrw_hup[host].uid
3428 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003429" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3430" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003432
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003433" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435
Bram Moolenaar85850f32019-07-19 22:05:51 +02003436" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003437" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003438" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003440" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003441" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3442fun! s:ExplorePatHls(pattern)
3443" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3444 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003445" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003446 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003448 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3449" call Dret("s:ExplorePatHls repat<".repat.">")
3450 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003451endfun
3452
3453" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003454" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003455" 0: (user: <mb>) bookmark current directory
3456" 1: (user: <gb>) change to the bookmarked directory
3457" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003458" 3: (browsing) records current directory history
3459" 4: (user: <u>) go up (previous) directory, using history
3460" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003461" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003462fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003463" 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 +02003464 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3465" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3466 return
3467 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003468
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003469 let ykeep = @@
3470 let curbufnr = bufnr("%")
3471
Bram Moolenaar9964e462007-05-05 17:54:07 +00003472 if a:chg == 0
3473 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003474" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003475 if exists("s:netrwmarkfilelist_{curbufnr}")
3476 call s:NetrwBookmark(0)
3477 echo "bookmarked marked files"
3478 else
3479 call s:MakeBookmark(a:curdir)
3480 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003481 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003482
KSR-Yasudaf4498252023-10-06 03:34:17 +09003483 try
3484 call s:NetrwBookHistSave()
3485 catch
3486 endtry
3487
Bram Moolenaar9964e462007-05-05 17:54:07 +00003488 elseif a:chg == 1
3489 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003490" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003491 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003492" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003493 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003494 else
3495 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3496 endif
3497
3498 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003499" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003500 let didwork= 0
3501 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003503 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003505 let cnt= 1
3506 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003507" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003508 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003509 let didwork = 1
3510 let cnt = cnt + 1
3511 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 endif
3513
3514 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003515 " Note: history is saved only when PerformListing is done;
3516 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3517 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003518 let first = 1
3519 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003520 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003521 while ( first || cnt != g:netrw_dirhistcnt )
3522" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003523 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003524" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003525 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 let didwork= 1
3527 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003528 let histcnt = histcnt + 1
3529 let first = 0
3530 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 if cnt < 0
3532 let cnt= cnt + g:netrw_dirhistmax
3533 endif
3534 endwhile
3535 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003536 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 if didwork
3539 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3540 endif
3541
3542 elseif a:chg == 3
3543 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003545 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 +02003546 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003547 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3548 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003549 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003551 endif
3552
3553 elseif a:chg == 4
3554 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003555" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003556 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003557 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3558 if g:netrw_dirhistcnt < 0
3559 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 endif
3561 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003563 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003564 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3565" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003566 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003567 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003568" call Decho("setl ma noro",'~'.expand("<slnum>"))
3569 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003570 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003571" call Decho("setl nomod",'~'.expand("<slnum>"))
3572" 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 +00003573 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003574" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3575 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003576 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003577 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003579 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003581 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003582 echo "Sorry, no predecessor directory exists yet"
3583 endif
3584
3585 elseif a:chg == 5
3586 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003587" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003588 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003589 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3590 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3591" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003592 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003593" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003594 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595 sil! NetrwKeepj %d _
3596" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3597" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003598 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599" 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 +02003600 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3602 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003603 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003604 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3605 if g:netrw_dirhistcnt < 0
3606 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003607 endif
3608 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003609 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003610 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003611 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003613 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003614
3615 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003616" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003617 if exists("s:netrwmarkfilelist_{curbufnr}")
3618 call s:NetrwBookmark(1)
3619 echo "removed marked files from bookmarks"
3620 else
3621 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622 let iremove = v:count
3623 let dremove = g:netrw_bookmarklist[iremove - 1]
3624" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003625 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003626" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3627 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3628 echo "removed ".dremove." from g:netrw_bookmarklist"
3629" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003631" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003632
3633 try
3634 call s:NetrwBookHistSave()
3635 catch
3636 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003637 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003638 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003639 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003640 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003641" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642endfun
3643
3644" ---------------------------------------------------------------------
3645" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003646" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647" Sister function: s:NetrwBookHistSave()
3648fun! s:NetrwBookHistRead()
3649" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003650 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003651" 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 +02003652 return
3653 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003654 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655
3656 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003657 if !exists("s:netrw_initbookhist")
3658 let home = s:NetrwHome()
3659 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003660 if filereadable(s:NetrwFile(savefile))
3661" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003662 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664
3665 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003666 if g:netrw_dirhistmax > 0
3667 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003668 if filereadable(s:NetrwFile(savefile))
3669" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003670 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003671 endif
3672 let s:netrw_initbookhist= 1
3673 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003674 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003676
Bram Moolenaar97d62492012-11-15 21:28:22 +01003677 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003678" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3679" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680" call Dret("s:NetrwBookHistRead")
3681endfun
3682
3683" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003685" Sister function: s:NetrwBookHistRead()
3686" I used to do this via viminfo but that appears to
3687" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003688" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3689" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003691fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003693 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003695 return
3696 endif
3697
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003701
3702 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003705 if g:netrw_use_noswf
3706 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3707 else
3708 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3709 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003710 setl nocin noai noci magic nospell nohid wig= noaw
3711 setl ma noro write
3712 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003713 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003714
Bram Moolenaar85850f32019-07-19 22:05:51 +02003715 " rename enew'd file: .netrwhist -- no attempt to merge
3716 " record dirhistmax and current dirhistcnt
3717 " save history
3718" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003719 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003720 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003721 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3722 if g:netrw_dirhistmax > 0
3723 let lastline = line("$")
3724 let cnt = g:netrw_dirhistcnt
3725 let first = 1
3726 while ( first || cnt != g:netrw_dirhistcnt )
3727 let lastline= lastline + 1
3728 if exists("g:netrw_dirhist_{cnt}")
3729 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3730" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3731 endif
3732 let first = 0
3733 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3734 if cnt < 0
3735 let cnt= cnt + g:netrw_dirhistmax
3736 endif
3737 endwhile
3738 exe "sil! w! ".savefile
3739" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3740 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741
Bram Moolenaar85850f32019-07-19 22:05:51 +02003742 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003743 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003745" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 " merge and write .netrwbook
3747 let savefile= s:NetrwHome()."/.netrwbook"
3748
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003749 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003751 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 for bdm in booklist
3753 if index(g:netrw_bookmarklist,bdm) == -1
3754 call add(g:netrw_bookmarklist,bdm)
3755 endif
3756 endfor
3757 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 endif
3759
3760 " construct and save .netrwbook
3761 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003762 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003763" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003764 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003765
3766 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003767 let bgone= bufnr("%")
3768 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003769 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003770
3771" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003772endfun
3773
3774" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3776" list of the contents of a local or remote directory. It is assumed that the
3777" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3778" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003779" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003780fun! s:NetrwBrowse(islocal,dirname)
3781 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003782" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003783" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3784" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3785" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003786
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003787 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3788 " This is useful when one edits a local file, then :e ., then :Rex
3789 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3790 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003791" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003792 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003794 " s:NetrwBrowse : initialize history {{{3
3795 if !exists("s:netrw_initbookhist")
3796 NetrwKeepj call s:NetrwBookHistRead()
3797 endif
3798
3799 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003800 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003802" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003803 else
3804 let dirname= a:dirname
3805 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806
Bram Moolenaar85850f32019-07-19 22:05:51 +02003807 " repoint t:netrw_lexbufnr if appropriate
3808 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3809" call Decho("set repointlexbufnr to true!")
3810 let repointlexbufnr= 1
3811 endif
3812
3813 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814 if exists("s:netrw_skipbrowse")
3815 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003816" 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 +01003817" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818 return
3819 endif
3820 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003821 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822" call Dret("s:NetrwBrowse : missing shellescape()")
3823 return
3824 endif
3825 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827" call Dret("s:NetrwBrowse : missing fnameescape()")
3828 return
3829 endif
3830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003832 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003833
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003835 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3836 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3837" call Decho("clearing marked files",'~'.expand("<slnum>"))
3838 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3839 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003840 endif
3841
3842 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003843 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003844" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3845" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003846 if s:NetrwLcd(dirname)
3847" call Dret("s:NetrwBrowse : lcd failure")
3848 return
3849 endif
3850 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003851" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852
Bram Moolenaar5c736222010-01-06 20:54:52 +01003853 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003854 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003855" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003859 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003861" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862
3863 " remove any filetype indicator from end of dirname, except for the
3864 " "this is a directory" indicator (/).
3865 " There shouldn't be one of those here, anyway.
3866 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 call s:RemotePathAnalysis(dirname)
3869
3870 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3871 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003872 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003874" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875 let b:netrw_curdir = dirname
3876 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003877 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3879 sil call netrw#NetRead(2,url)
3880 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003881" call Decho("url<".url.">",'~'.expand("<slnum>"))
3882" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3883" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003884 if s:path =~ '.bz2'
3885 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3886 elseif s:path =~ '.gz'
3887 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3888 elseif s:path =~ '.gz'
3889 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3890 else
3891 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893 endif
3894
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003897 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003899 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003900" 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 +00003901
Bram Moolenaar446cb832008-06-24 21:56:24 +00003902" call Dret("s:NetrwBrowse : file<".s:fname.">")
3903 return
3904 endif
3905
Bram Moolenaaradc21822011-04-01 18:03:16 +02003906 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907 call s:UseBufWinVars()
3908
3909 " set up some variables {{{3
3910 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003911 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912 let s:last_sort_by = g:netrw_sort_by
3913
3914 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003915 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916
Bram Moolenaar97d62492012-11-15 21:28:22 +01003917 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003919 let svpos = winsaveview()
3920" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003922
Bram Moolenaar446cb832008-06-24 21:56:24 +00003923 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003924 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3925 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3926" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3927" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3928 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3929 else
3930" " call Decho("2match none",'~'.expand("<slnum>"))
3931 2match none
3932 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003933 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003934 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003935 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003937 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003939" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003940 return
3941 endif
3942
3943 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003945 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 if b:netrw_curdir =~ '[/\\]$'
3947 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3948 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003949 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003950 let b:netrw_curdir= b:netrw_curdir."/"
3951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003952 if b:netrw_curdir == ''
3953 if has("amiga")
3954 " On the Amiga, the empty string connotes the current directory
3955 let b:netrw_curdir= getcwd()
3956 else
3957 " under unix, when the root directory is encountered, the result
3958 " from the preceding substitute is an empty string.
3959 let b:netrw_curdir= '/'
3960 endif
3961 endif
3962 if !a:islocal && b:netrw_curdir !~ '/$'
3963 let b:netrw_curdir= b:netrw_curdir.'/'
3964 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003965" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966
3967 " ------------
3968 " (local only) {{{3
3969 " ------------
3970 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003971" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972
3973 " Set up ShellCmdPost handling. Append current buffer to browselist
3974 call s:LocalFastBrowser()
3975
3976 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3977 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3979" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003981 if s:NetrwLcd(b:netrw_curdir)
3982" call Dret("s:NetrwBrowse : lcd failure")
3983 return
3984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985 endif
3986 endif
3987
3988 " --------------------------------
3989 " remote handling: {{{3
3990 " --------------------------------
3991 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993
Bram Moolenaar97d62492012-11-15 21:28:22 +01003994 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003996 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003997 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003998" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003999 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4000 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4001 if dirname !~ '/$'
4002 let dirname= dirname.'/'
4003 endif
4004 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004007 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004008" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004009 endif
4010
4011 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4012 if dirname !~ dirpat
4013 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004014 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004015 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004016 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004017" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004018 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" 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 +00004020" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4021 return
4022 endif
4023 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025 endif " (additional remote handling)
4026
Bram Moolenaar85850f32019-07-19 22:05:51 +02004027 " -------------------------------
4028 " Perform Directory Listing: {{{3
4029 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004030 NetrwKeepj call s:NetrwMaps(a:islocal)
4031 NetrwKeepj call s:NetrwCommands(a:islocal)
4032 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004034 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004035 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004036" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4037
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038 " If there is a rexposn: restore position with rexposn
4039 " Otherwise : set rexposn
4040 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004041" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4042 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4043 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4044 NetrwKeepj exe w:netrw_bannercnt
4045 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046 else
4047 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4048 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004049 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004050 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004051" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004052 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004053 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004054
Bram Moolenaar85850f32019-07-19 22:05:51 +02004055 " repoint t:netrw_lexbufnr if appropriate
4056 if exists("repointlexbufnr")
4057 let t:netrw_lexbufnr= bufnr("%")
4058" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4059 endif
4060
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004061 " restore position
4062 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004063" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4064 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004065 endif
4066
Bram Moolenaara6878372014-03-22 21:02:50 +01004067 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004068 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4069 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004070" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4071" 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 +02004072" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004073 return
4074endfun
4075
4076" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004077" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4078" may not apply correctly; ie. netrw's idea of the current directory may
4079" differ from vim's. This function insures that netrw's idea of the current
4080" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004082fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004083" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4084" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4085" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4086" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4087" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004088
4089 " clean up any leading treedepthstring
4090 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4091 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004092" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004093 else
4094 let fname= a:fname
4095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004096
4097 if g:netrw_keepdir
4098 " vim's idea of the current directory possibly may differ from netrw's
4099 if !exists("b:netrw_curdir")
4100 let b:netrw_curdir= getcwd()
4101 endif
4102
Nir Lichtman1e34b952024-05-08 19:19:34 +02004103 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004107" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108 else
4109 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004110 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004111" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112 endif
4113
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004117" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118 else
4119 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004120 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004121" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004122 endif
4123 else
4124 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004125 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4127" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4128" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004129 endif
4130
Bram Moolenaar85850f32019-07-19 22:05:51 +02004131" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004132 return ret
4133endfun
4134
4135" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136" s:NetrwFileInfo: supports qf (query for file information) {{{2
4137fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004138" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004139 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004141 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004142 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004143 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004144 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004145 let lsopt= "-lsadh --si"
4146 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004147" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004149
4150 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004153
Bram Moolenaara6878372014-03-22 21:02:50 +01004154 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004155 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
4158 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004161
Bram Moolenaar446cb832008-06-24 21:56:24 +00004162 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004163" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 endif
4167 else
4168 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4170 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171 let fname= substitute(a:fname,".$","","")
4172 else
4173 let fname= a:fname
4174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004175 let t = getftime(s:NetrwFile(fname))
4176 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004177 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004178 let sz= s:NetrwHumanReadable(sz)
4179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4181" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004182 endif
4183 else
4184 echo "sorry, \"qf\" not supported yet for remote files"
4185 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004186 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187" call Dret("s:NetrwFileInfo")
4188endfun
4189
4190" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004191" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4192fun! s:NetrwFullPath(filename)
4193" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4194 let filename= a:filename
4195 if filename !~ '^/'
4196 let filename= resolve(getcwd().'/'.filename)
4197 endif
4198 if filename != "/" && filename =~ '/$'
4199 let filename= substitute(filename,'/$','','')
4200 endif
4201" " call Dret("s:NetrwFullPath <".filename.">")
4202 return filename
4203endfun
4204
4205" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004206" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004208" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004209" 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 +00004210fun! s:NetrwGetBuffer(islocal,dirname)
4211" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004212" 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 +02004213" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4214" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215 let dirname= a:dirname
4216
4217 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004218" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004219 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004220" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004221 let s:netrwbuf= {}
4222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004223" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4224" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4225
4226 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4227 let bufnum = -1
4228
4229 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4230 if has_key(s:netrwbuf,"NetrwTreeListing")
4231 let bufnum= s:netrwbuf["NetrwTreeListing"]
4232 else
4233 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4234 endif
4235" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4236 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004237 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004238 let bufnum= -1
4239 endif
4240 elseif bufnr("NetrwTreeListing") != -1
4241 let bufnum= bufnr("NetrwTreeListing")
4242" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4243 else
4244" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4245 let bufnum= -1
4246 endif
4247
4248 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004249 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004250" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004251 if !bufexists(bufnum)
4252 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4253 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004257" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004258 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4261
Bram Moolenaar71badf92023-04-22 22:40:14 +01004262 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004263 " IF the buffer already has the desired name
4264 " AND it is empty
4265 let curbuf = bufname("%")
4266 if curbuf == '.'
4267 let curbuf = getcwd()
4268 endif
4269" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004270" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004271" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4272" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4273" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4274" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4275 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004276" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4277 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004278 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004279" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004280 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004281 " 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 +00004282
4283 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004284 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004285" 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 +00004286 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004288 " name the buffer
4289 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4290 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004292 let w:netrw_treebufnr = bufnr("%")
4293 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004294 if g:netrw_use_noswf
4295 setl nobl bt=nofile noswf
4296 else
4297 setl nobl bt=nofile
4298 endif
4299 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4300 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4301 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4302 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004303" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004305 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004306 " enter the new buffer into the s:netrwbuf dictionary
4307 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4308" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4309" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312
4313 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004314" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004315 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004317 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004318
4319 if &ft == "netrw"
4320" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4321 exe "sil! NetrwKeepj noswapfile b ".bufnum
4322" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004324" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4325 call s:NetrwEditBuf(bufnum)
4326" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004328" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004330 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004332
4333 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336 if line("$") <= 1 && getline(1) == ""
4337 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004338 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339" 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>"))
4340" 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 +01004341" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4342 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343
Bram Moolenaar97d62492012-11-15 21:28:22 +01004344 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004345" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004346 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004347 sil NetrwKeepj %d _
4348" 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>"))
4349" 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 +01004350" 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 +00004351 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004352
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4355" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004356 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004357 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004358 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359" 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>"))
4360" 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 +01004361" 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 +00004362 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004363
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004365" 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>"))
4366" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4367" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 return 1
4369 endif
4370 endif
4371
4372 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4373 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4374 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4375 " med 1 D H
4376 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004377" 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 +00004378 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004379 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004380 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381
4382 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4384" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4385 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004387" 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>"))
4388" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4389" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 return 0
4391endfun
4392
4393" ---------------------------------------------------------------------
4394" s:NetrwGetcwd: get the current directory. {{{2
4395" Change backslashes to forward slashes, if any.
4396" If doesc is true, escape certain troublesome characters
4397fun! s:NetrwGetcwd(doesc)
4398" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4399 let curdir= substitute(getcwd(),'\\','/','ge')
4400 if curdir !~ '[\/]$'
4401 let curdir= curdir.'/'
4402 endif
4403 if a:doesc
4404 let curdir= fnameescape(curdir)
4405 endif
4406" call Dret("NetrwGetcwd <".curdir.">")
4407 return curdir
4408endfun
4409
4410" ---------------------------------------------------------------------
4411" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4412fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004413" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4414" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4415 let keepsol= &l:sol
4416 setl nosol
4417
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 call s:UseBufWinVars()
4419
4420 " insure that w:netrw_liststyle is set up
4421 if !exists("w:netrw_liststyle")
4422 if exists("g:netrw_liststyle")
4423 let w:netrw_liststyle= g:netrw_liststyle
4424 else
4425 let w:netrw_liststyle= s:THINLIST
4426 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004427" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428 endif
4429
4430 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4431 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004432" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004433 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434 let dirname= "./"
4435 let curline= getline('.')
4436
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004437 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004438 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 let s:netrw_skipbrowse= 1
4440 echo 'Pressing "s" also works'
4441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004442 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443 let s:netrw_skipbrowse= 1
4444 echo 'Press "S" to edit sorting sequence'
4445
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004446 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004447 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004450 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004451 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452 let s:netrw_skipbrowse= 1
4453 echo 'Pressing "a" also works'
4454
4455 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004456 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457 endif
4458
4459 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004460" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004461 NetrwKeepj norm! 0
4462 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463
4464 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004466 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4468
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004469 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004471 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004472 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473
4474 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004475" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476 let dirname= getline('.')
4477
4478 if !exists("b:netrw_cpf")
4479 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 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 +01004481 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004482" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 endif
4484
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004485" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4488" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004490 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 else
4492 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004493 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 endif
Enno3146d632024-07-04 19:44:42 +02004495
4496 let dict={}
4497 " save the unnamed register and register 0-9 and a
4498 let dict.a=[getreg('a'), getregtype('a')]
4499 for i in range(0, 9)
4500 let dict[i] = [getreg(i), getregtype(i)]
4501 endfor
4502 let dict.unnamed = [getreg(''), getregtype('')]
4503
Bram Moolenaarc236c162008-07-13 17:41:49 +00004504 let eofname= filestart + b:netrw_cpf + 1
4505 if eofname <= col("$")
4506 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004507 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004508 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004509 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004510 endif
Enno3146d632024-07-04 19:44:42 +02004511
Bram Moolenaar446cb832008-06-24 21:56:24 +00004512 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004513 call s:RestoreRegister(dict)
4514
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004515" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004516 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004517" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 endif
4519
4520 " symlinks are indicated by a trailing "@". Remove it before further processing.
4521 let dirname= substitute(dirname,"@$","","")
4522
4523 " executables are indicated by a trailing "*". Remove it before further processing.
4524 let dirname= substitute(dirname,"\*$","","")
4525
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004526 let &l:sol= keepsol
4527
Bram Moolenaar446cb832008-06-24 21:56:24 +00004528" call Dret("s:NetrwGetWord <".dirname.">")
4529 return dirname
4530endfun
4531
4532" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004533" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4534" g:netrw_bufsettings will be used after the listing is produced.
4535" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536fun! s:NetrwListSettings(islocal)
4537" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004538" 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 +00004539 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004540" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4541 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4542 setl bt=nofile nobl ma nonu nowrap noro nornu
4543 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004545 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004547" call Dredir("ls!","s:NetrwListSettings")
4548" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004549 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004550 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004552 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004553 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004554 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004556" 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 +00004557" call Dret("s:NetrwListSettings")
4558endfun
4559
4560" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004561" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004562" islocal=0: remote browsing
4563" =1: local browsing
4564fun! s:NetrwListStyle(islocal)
4565" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004566
Bram Moolenaar97d62492012-11-15 21:28:22 +01004567 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568 let fname = s:NetrwGetWord()
4569 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004570 let svpos = winsaveview()
4571" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004573" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4574" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4575" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576
Bram Moolenaar85850f32019-07-19 22:05:51 +02004577 " repoint t:netrw_lexbufnr if appropriate
4578 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4579" call Decho("set repointlexbufnr to true!")
4580 let repointlexbufnr= 1
4581 endif
4582
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 if w:netrw_liststyle == s:THINLIST
4584 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004585" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004586 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4587
4588 elseif w:netrw_liststyle == s:LONGLIST
4589 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004590" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004591 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4592
4593 elseif w:netrw_liststyle == s:WIDELIST
4594 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004595" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4597
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004598 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004599" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004600 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4601
4602 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004603 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004604 let g:netrw_liststyle = s:THINLIST
4605 let w:netrw_liststyle = g:netrw_liststyle
4606 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4607 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004608 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004610
4611 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4613 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004614 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004616 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" 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 +00004618
4619 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004620" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004621 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004622 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004623
Bram Moolenaar85850f32019-07-19 22:05:51 +02004624 " repoint t:netrw_lexbufnr if appropriate
4625 if exists("repointlexbufnr")
4626 let t:netrw_lexbufnr= bufnr("%")
4627" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4628 endif
4629
Bram Moolenaar13600302014-05-22 18:26:40 +02004630 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004631" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4632 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004633 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004634
4635" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4636endfun
4637
4638" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004639" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4640fun! s:NetrwBannerCtrl(islocal)
4641" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4642
Bram Moolenaar97d62492012-11-15 21:28:22 +01004643 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004644 " toggle the banner (enable/suppress)
4645 let g:netrw_banner= !g:netrw_banner
4646
4647 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004648 let svpos= winsaveview()
4649" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004650 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4651
4652 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004653 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4654 let fname= s:NetrwGetWord()
4655 sil NetrwKeepj $
4656 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4657" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4658 if result <= 0 && exists("w:netrw_bannercnt")
4659 exe "NetrwKeepj ".w:netrw_bannercnt
4660 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004662 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004663" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4664endfun
4665
4666" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004667" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4668"
4669" No bang: enters files/directories into Netrw's bookmark system
4670" No argument and in netrw buffer:
4671" if there are marked files: bookmark marked files
4672" otherwise : bookmark file/directory under cursor
4673" No argument and not in netrw buffer: bookmarks current open file
4674" Has arguments: globs them individually and bookmarks them
4675"
4676" With bang: deletes files/directories from Netrw's bookmark system
4677fun! s:NetrwBookmark(del,...)
4678" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4679 if a:0 == 0
4680 if &ft == "netrw"
4681 let curbufnr = bufnr("%")
4682
4683 if exists("s:netrwmarkfilelist_{curbufnr}")
4684 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004685" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004686 let svpos = winsaveview()
4687" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004688 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004689 for fname in s:netrwmarkfilelist_{curbufnr}
4690 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4691 endfor
4692 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4693 call s:NetrwUnmarkList(curbufnr,curdir)
4694 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004695" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4696 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 else
4698 let fname= s:NetrwGetWord()
4699 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4700 endif
4701
4702 else
4703 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004704" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004705 let fname= expand("%")
4706 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4707 endif
4708
4709 else
4710 " bookmark specified files
4711 " attempts to infer if working remote or local
4712 " by deciding if the current file begins with an url
4713 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004714 let islocal= expand("%") !~ '^\a\{3,}://'
4715" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004716 let i = 1
4717 while i <= a:0
4718 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004719 if v:version > 704 || (v:version == 704 && has("patch656"))
4720 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004722 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004723 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004724 else
4725 let mbfiles= [a:{i}]
4726 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004727" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004728 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004729" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004730 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4731 endfor
4732 let i= i + 1
4733 endwhile
4734 endif
4735
4736 " update the menu
4737 call s:NetrwBookmarkMenu()
4738
4739" call Dret("s:NetrwBookmark")
4740endfun
4741
4742" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004743" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4744" .2.[cnt] for bookmarks, and
4745" .3.[cnt] for history
4746" (see s:NetrwMenu())
4747fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004748 if !exists("s:netrw_menucnt")
4749 return
4750 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004751" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004752
4753 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004754 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004755 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004756" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004757 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4758 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004759 endif
4760 if !exists("s:netrw_initbookhist")
4761 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004762 endif
4763
4764 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004765 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004766 let cnt= 1
4767 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004768" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004769 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004770
4771 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004772 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004773
4774 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004775 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 +01004776 let cnt= cnt + 1
4777 endfor
4778
4779 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004780
4781 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 let first = 1
4785 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004786 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004788 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004789 if exists("g:netrw_dirhist_{cnt}")
4790 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004791" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004792 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4793 endif
4794 let first = 0
4795 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4796 if cnt < 0
4797 let cnt= cnt + g:netrw_dirhistmax
4798 endif
4799 endwhile
4800 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004801
Bram Moolenaar9964e462007-05-05 17:54:07 +00004802 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004803" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004804endfun
4805
4806" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004807" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4808" directory and a new directory name. Also, if the
4809" "new directory name" is actually a file,
4810" NetrwBrowseChgDir() edits the file.
4811fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004812" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004813" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004814
Bram Moolenaar97d62492012-11-15 21:28:22 +01004815 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816 if !exists("b:netrw_curdir")
4817 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4818 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004819 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004820" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4821" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004822" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004824 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004825 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004826" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004827
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004828 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004829" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004830 call s:SavePosn(s:netrw_posn)
4831 NetrwKeepj call s:NetrwOptionsSave("s:")
4832 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004833 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004834 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004835 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004836 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004837 endif
4838 let newdir = a:newdir
4839 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004840 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004841" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004842" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004843" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004844
4845 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004846" call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004847 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004848" call Decho("win#".winnr()." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004849 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004850 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" call Decho("#1: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004852 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004853" call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004854 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004855 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004856 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004857 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004858" 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 +01004859 endif
4860 endif
4861" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004862" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004863 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004864
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 " set up o/s-dependent directory recognition pattern
4866 if has("amiga")
4867 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004868 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869 let dirpat= '[\/]$'
4870 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004871" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004872
4873 if dirname !~ dirpat
4874 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004875 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004877" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878 endif
4879
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004880" call Decho("[newdir<".newdir."> ".((newdir =~ dirpat)? "=~" : "!~")." dirpat<".dirpat.">] && [islocal=".a:islocal."] && [newdir is ".(isdirectory(s:NetrwFile(newdir))? "" : "not ")."a directory]",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004881 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004882 " ------------------------------
4883 " NetrwBrowseChgDir: edit a file {{{3
4884 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004885" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004886
Bram Moolenaar97d62492012-11-15 21:28:22 +01004887 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004888 let s:rexposn_{bufnr("%")}= winsaveview()
4889" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004890" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4891" call Decho("edit-a-file: w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')." w:netrw_treedict:".(exists("w:netrw_treedict")? "exists" : 'n/a')." newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004892
Bram Moolenaar446cb832008-06-24 21:56:24 +00004893 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004894" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4895" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004896" let newdir = s:NetrwTreePath(s:netrw_treetop)
4897" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004898 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004899 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4900" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4901 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 if dirname =~ '/$'
4903 let dirname= dirname.newdir
4904 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004905 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4908" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004910" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004912 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004915" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004916 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004917 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004918" call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004919 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004920 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004921 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004922" " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004923 if type(g:netrw_browse_split) == 3
4924 " open file in server
4925 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004926" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004927 call s:NetrwServerEdit(a:islocal,dirname)
4928" call Dret("s:NetrwBrowseChgDir")
4929 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004930
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004931 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004932 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004933" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004934 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4935 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004936 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004937 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004938 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004939 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004940
Bram Moolenaar446cb832008-06-24 21:56:24 +00004941 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004942 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004943" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004944 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4945 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004946 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004947 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004948 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004949 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004950
Bram Moolenaar446cb832008-06-24 21:56:24 +00004951 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004952 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004953" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004954 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004955 if !exists("b:netrw_curdir")
4956 let b:netrw_curdir= getcwd()
4957 endif
4958 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004959
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004961 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004962" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004964 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004966 return
4967 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004968 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004969
Bram Moolenaar9964e462007-05-05 17:54:07 +00004970 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004972" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004973 call s:NetrwMenu(0)
4974 " optional change to window
4975 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004976" call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004977 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004978 " if g:netrw_chgwin is set to one more than the last window, then
4979 " vertically split the last window to make that window available.
4980 let curwin= winnr()
4981 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4982 vs
4983 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004984 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004985 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004986 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004987 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004988 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004989
Bram Moolenaar9964e462007-05-05 17:54:07 +00004990 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004991
Bram Moolenaar446cb832008-06-24 21:56:24 +00004992 " the point where netrw actually edits the (local) file
4993 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004994 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004995 if !&mod
4996 " if e the new file would fail due to &mod, then don't change any of the flags
4997 let dolockout= 1
4998 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004999 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005000" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005001 " some like c-^ to return to the last edited file
5002 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005003 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5004 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005005 call s:NetrwEditFile("e","",dirname)
5006" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005007 " COMBAK -- cuc cul related
5008 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005009 if &hidden || &bufhidden == "hide"
5010 " file came from vim's hidden storage. Don't "restore" options with it.
5011 let dorestore= 0
5012 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005013 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005015 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005016
5017 " handle g:Netrw_funcref -- call external-to-netrw functions
5018 " This code will handle g:Netrw_funcref as an individual function reference
5019 " or as a list of function references. It will ignore anything that's not
5020 " a function reference. See :help Funcref for information about function references.
5021 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005024" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005025 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005026 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005027" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005028 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005029 if type(Fncref) == 2
5030 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005031 endif
5032 endfor
5033 endif
5034 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005035 endif
5036
5037 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005038 " ----------------------------------------------------
5039 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5040 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005041" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005042 let dirname = newdir
5043 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005044 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005045 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005046
5047 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005048 " ---------------------------------------------
5049 " NetrwBrowseChgDir: refresh the directory list {{{3
5050 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005051" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005052 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005053 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005054
5055 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005056 " --------------------------------------
5057 " NetrwBrowseChgDir: go up one directory {{{3
5058 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005059" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005060
5061 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5062 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005063" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5064" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005065 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005067 endif
5068
5069 if has("amiga")
5070 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005072 if a:islocal
5073 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5074 let dirname= substitute(dirname,'/$','','')
5075 else
5076 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5077 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005078" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079
Nir Lichtman1e34b952024-05-08 19:19:34 +02005080 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005081 " windows
5082 if a:islocal
5083 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5084 if dirname == ""
5085 let dirname= '/'
5086 endif
5087 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005088 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005089 endif
5090 if dirname =~ '^\a:$'
5091 let dirname= dirname.'/'
5092 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005093" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005094
Bram Moolenaar446cb832008-06-24 21:56:24 +00005095 else
5096 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005097" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005098 if a:islocal
5099 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5100 if dirname == ""
5101 let dirname= '/'
5102 endif
5103 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005104 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005106" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005107 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005108 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005109 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005110
5111 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005112 " --------------------------------------
5113 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5114 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005115" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5117" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005118 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005119 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005120" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5121 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005122 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005123 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005124" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005125 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005126 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005127" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128
5129 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005130" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005132" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 let haskey= 1
5134 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005135" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 endif
5137
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005138 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005139" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005140 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 if has_key(w:netrw_treedict,treedir."/")
5142 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 let haskey = 1
5145 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005146" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 endif
5148 endif
5149
5150 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005151" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 if !haskey && treedir =~ '/$'
5153 let treedir= substitute(treedir,'/$','','')
5154 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005155" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 let haskey = 1
5157 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005158" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 endif
5160 endif
5161
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 if haskey
5164 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005166 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005167" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5168" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005169 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005170 else
5171 " go down one directory
5172 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005173" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5174" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005176 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005177" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005178 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005179
5180 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005181 " ----------------------------------------
5182 " NetrwBrowseChgDir: Go down one directory {{{3
5183 " ----------------------------------------
5184 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005185" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005186 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005187 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005188 endif
5189
Bram Moolenaar97d62492012-11-15 21:28:22 +01005190 " --------------------------------------
5191 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5192 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005193 if dorestore
5194 " dorestore is zero'd when a local file was hidden or bufhidden;
5195 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005197 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005198" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005200 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005203 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5205" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005206 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005208 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005209" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5210" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005211 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005212" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005213 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005214 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005215 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005216 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005217
Bram Moolenaar446cb832008-06-24 21:56:24 +00005218" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5219 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005220endfun
5221
5222" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005223" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5224" for thin, long, and wide: cursor placed just after banner
5225" for tree, keeps cursor on current filename
5226fun! s:NetrwBrowseUpDir(islocal)
5227" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005228 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5229 " this test needed because occasionally this function seems to be incorrectly called
5230 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005231 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005232 " directories.
5233" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5234 return
5235 endif
5236
Bram Moolenaara6878372014-03-22 21:02:50 +01005237 norm! 0
5238 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005239" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005240 let curline= getline(".")
5241 let swwline= winline() - 1
5242 if exists("w:netrw_treetop")
5243 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005244 elseif exists("b:netrw_curdir")
5245 let w:netrw_treetop= b:netrw_curdir
5246 else
5247 let w:netrw_treetop= getcwd()
5248 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005249 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005250 let curfile = getline(".")
5251 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005252 if a:islocal
5253 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5254 else
5255 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5256 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005257" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5258" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5259 if w:netrw_treetop == '/'
5260 keepj call search('^\M'.curfile,"w")
5261 elseif curfile == '../'
5262 keepj call search('^\M'.curfile,"wb")
5263 else
5264" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5265 while 1
5266 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5267 let treepath= s:NetrwTreePath(w:netrw_treetop)
5268" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5269 if treepath == curpath
5270 break
5271 endif
5272 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005273 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005274
Bram Moolenaara6878372014-03-22 21:02:50 +01005275 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005276" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005277 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005278 if exists("b:netrw_curdir")
5279 let curdir= b:netrw_curdir
5280 else
5281 let curdir= expand(getcwd())
5282 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005283 if a:islocal
5284 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5285 else
5286 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5287 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005288 call s:RestorePosn(s:netrw_posn)
5289 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005290 let curdir= '\<'. escape(curdir, '~'). '/'
5291 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005292 endif
5293" call Dret("s:NetrwBrowseUpDir")
5294endfun
5295
5296" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005297" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005298" given filename; typically this means given their extension.
5299" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005300fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005301 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005302" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005303
Bram Moolenaar91359012019-11-30 17:57:03 +01005304 if a:remote == 0 && isdirectory(a:fname)
5305 " if its really just a local directory, then do a "gf" instead
5306" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005307" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5308 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005309" call Dret("netrw#BrowseX")
5310 return
5311 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5312 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5313" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5314" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5315" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5316" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5317 norm! gf
5318" call Dret("netrw#BrowseX")
5319 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005320 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005321" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005322
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005323 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5324 let remote = a:remote
5325 else
5326 let remote = 0
5327 endif
5328
Bram Moolenaar97d62492012-11-15 21:28:22 +01005329 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005330 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005331" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005332
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005333 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5334 let awkeep = &aw
5335 set noaw
5336
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337 " special core dump handler
5338 if a:fname =~ '/core\(\.\d\+\)\=$'
5339 if exists("g:Netrw_corehandler")
5340 if type(g:Netrw_corehandler) == 2
5341 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005342" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005343 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005344 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005346" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005347 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005348 if type(Fncref) == 2
5349 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005350 endif
5351 endfor
5352 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005353" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005354 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005355 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005356 let &aw= awkeep
5357" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005358 return
5359 endif
5360 endif
5361
Bram Moolenaar446cb832008-06-24 21:56:24 +00005362 " set up the filename
5363 " (lower case the extension, make a local copy of a remote file)
5364 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005365 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005366 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005367 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005368 if exten =~ "[\\/]"
5369 let exten= ""
5370 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005371" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005372
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005373 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005374 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005375" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005376 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005377 call netrw#NetRead(3,a:fname)
5378 " attempt to rename tempfile
5379 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005380 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005381" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5382" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005383 if s:netrw_tmpfile != newname && newname != ""
5384 if rename(s:netrw_tmpfile,newname) == 0
5385 " renaming succeeded
5386" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5387 let fname= newname
5388 else
5389 " renaming failed
5390" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5391 let fname= s:netrw_tmpfile
5392 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005393 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005394 let fname= s:netrw_tmpfile
5395 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005396 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005397" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005398 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005399 " special ~ handler for local
5400 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005401" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5402 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005403 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005404 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005405" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5406" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005407
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005408 " set up redirection (avoids browser messages)
5409 " by default, g:netrw_suppress_gx_mesg is true
5410 if g:netrw_suppress_gx_mesg
5411 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005412 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005413 let redir= substitute(&srr,"%s","nul","")
5414 else
5415 let redir= substitute(&srr,"%s","/dev/null","")
5416 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005417 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005418 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005420 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005422 else
5423 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005425" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005427 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005429" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005430 if g:netrw_browsex_viewer =~ '\s'
5431 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5432 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5433 let oviewer = ''
5434 let cnt = 1
5435 while !executable(viewer) && viewer != oviewer
5436 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5437 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5438 let cnt = cnt + 1
5439 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005440" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441 endwhile
5442 else
5443 let viewer = g:netrw_browsex_viewer
5444 let viewopt = ""
5445 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005446" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 endif
5448
5449 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005450" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005452" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453 let ret= netrwFileHandlers#Invoke(exten,fname)
5454
5455 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005456" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005457 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 let ret= v:shell_error
5459
Nir Lichtman1e34b952024-05-08 19:19:34 +02005460 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005461" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005462 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005463 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005464 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005465 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005466 else
5467 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5468 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005469 let ret= v:shell_error
5470
Bram Moolenaar97d62492012-11-15 21:28:22 +01005471 elseif has("win32unix")
5472 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005474 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005475" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005476 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005477 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005478" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005479 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005480 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005481" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005482 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005483 else
5484 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5485 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005486 let ret= v:shell_error
5487
Bram Moolenaar85850f32019-07-19 22:05:51 +02005488 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005489" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5490 if a:fname =~ '^https\=://'
5491 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5492 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005493" call Decho("fname<".fname.">")
5494" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005495 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5496
5497 else
5498 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5499 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005500 let ret= v:shell_error
5501
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005502 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5503" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5504 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5505 let ret= v:shell_error
5506
5507 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5508" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5509 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5510 let ret= v:shell_error
5511
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005512 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005513" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005514 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005515 let ret= v:shell_error
5516
5517 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005518" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005519 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005520 let ret= v:shell_error
5521
5522 else
5523 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005524" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 let ret= netrwFileHandlers#Invoke(exten,fname)
5526 endif
5527
5528 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5529 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005530" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531 let ret= netrwFileHandlers#Invoke(exten,fname)
5532 endif
5533
Bram Moolenaarc236c162008-07-13 17:41:49 +00005534 " restoring redraw! after external file handlers
5535 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005536
5537 " cleanup: remove temporary file,
5538 " delete current buffer if success with handler,
5539 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005540 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005542" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005543"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005544" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545" endif
5546
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005547 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005548 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005550 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005552 if use_ctrlo
5553 exe "sil! NetrwKeepj norm! \<c-o>"
5554 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005556" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005557 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005558 let @@ = ykeep
5559 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005560
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005561" call Dret("netrw#BrowseX")
5562endfun
5563
5564" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005565" netrw#GX: gets word under cursor for gx support {{{2
5566" See also: netrw#BrowseXVis
5567" netrw#BrowseX
5568fun! netrw#GX()
5569" call Dfunc("netrw#GX()")
5570 if &ft == "netrw"
5571 let fname= s:NetrwGetWord()
5572 else
5573 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5574 endif
5575" call Dret("netrw#GX <".fname.">")
5576 return fname
5577endfun
5578
5579" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005580" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5581fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005582 let dict={}
5583 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005584 norm! gv"ay
5585 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005586 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005587 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005588endfun
5589
5590" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005591" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5592" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5593" to become an unlisted buffer, so in that case don't bwipe it.
5594fun! s:NetrwBufRename(newname)
5595" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5596" call Dredir("ls!","s:NetrwBufRename (before rename)")
5597 let oldbufname= bufname(bufnr("%"))
5598" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5599
5600 if oldbufname != a:newname
5601" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5602 let b:junk= 1
5603" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5604 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005605" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005606 let oldbufnr= bufnr(oldbufname)
5607" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5608" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5609 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5610" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5611 exe "bwipe! ".oldbufnr
5612" else " Decho
5613" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005614" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5615" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5616" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005617 endif
5618" call Dredir("ls!","s:NetrwBufRename (after rename)")
5619" else " Decho
5620" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5621 endif
5622
5623" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5624endfun
5625
5626" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005627" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005628fun! netrw#CheckIfRemote(...)
5629" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5630 if a:0 > 0
5631 let curfile= a:1
5632 else
5633 let curfile= expand("%")
5634 endif
5635" call Decho("curfile<".curfile.">")
5636 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005637" call Dret("netrw#CheckIfRemote 1")
5638 return 1
5639 else
5640" call Dret("netrw#CheckIfRemote 0")
5641 return 0
5642 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005643endfun
5644
5645" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005646" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5647fun! s:NetrwChgPerm(islocal,curdir)
5648" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005649 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005650 call inputsave()
5651 let newperm= input("Enter new permission: ")
5652 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005653 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5654 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5655" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005656 call system(chgperm)
5657 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005658 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005659 endif
5660 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005661 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005662 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005663 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005664" call Dret("s:NetrwChgPerm")
5665endfun
5666
5667" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005668" s:CheckIfKde: checks if kdeinit is running {{{2
5669" Returns 0: kdeinit not running
5670" 1: kdeinit is running
5671fun! s:CheckIfKde()
5672" call Dfunc("s:CheckIfKde()")
5673 " seems kde systems often have gnome-open due to dependencies, even though
5674 " gnome-open's subsidiary display tools are largely absent. Kde systems
5675 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5676 if !exists("s:haskdeinit")
5677 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005678 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 if v:shell_error
5680 let s:haskdeinit = 0
5681 endif
5682 else
5683 let s:haskdeinit= 0
5684 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005685" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005686 endif
5687
5688" call Dret("s:CheckIfKde ".s:haskdeinit)
5689 return s:haskdeinit
5690endfun
5691
5692" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005693" s:NetrwClearExplore: clear explore variables (if any) {{{2
5694fun! s:NetrwClearExplore()
5695" call Dfunc("s:NetrwClearExplore()")
5696 2match none
5697 if exists("s:explore_match") |unlet s:explore_match |endif
5698 if exists("s:explore_indx") |unlet s:explore_indx |endif
5699 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5700 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5701 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5702 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5703 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5704 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5705 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5706" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005707" call Dret("s:NetrwClearExplore")
5708endfun
5709
5710" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005711" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5712fun! s:NetrwEditBuf(bufnum)
5713" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5714 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5715" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5716 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5717 else
5718" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005719 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005720 endif
5721" call Dret("s:NetrwEditBuf")
5722endfun
5723
5724" ---------------------------------------------------------------------
5725" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5726" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5727fun! s:NetrwEditFile(cmd,opt,fname)
5728" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5729 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5730" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5731 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5732 else
5733" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005734 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5735 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5736 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005737 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5738 endif
5739" call Dret("s:NetrwEditFile")
5740endfun
5741
5742" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005743" s:NetrwExploreListUniq: {{{2
5744fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005745" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005746
5747 " this assumes that the list is already sorted
5748 let newexplist= []
5749 for member in a:explist
5750 if !exists("uniqmember") || member != uniqmember
5751 let uniqmember = member
5752 let newexplist = newexplist + [ member ]
5753 endif
5754 endfor
5755
Bram Moolenaar15146672011-10-20 22:22:38 +02005756" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005757 return newexplist
5758endfun
5759
5760" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005761" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5762fun! s:NetrwForceChgDir(islocal,newdir)
5763" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005764 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005765 if a:newdir !~ '/$'
5766 " ok, looks like force is needed to get directory-style treatment
5767 if a:newdir =~ '@$'
5768 let newdir= substitute(a:newdir,'@$','/','')
5769 elseif a:newdir =~ '[*=|\\]$'
5770 let newdir= substitute(a:newdir,'.$','/','')
5771 else
5772 let newdir= a:newdir.'/'
5773 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005774" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005775 else
5776 " should already be getting treatment as a directory
5777 let newdir= a:newdir
5778 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005779 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005780 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005781 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005782" call Dret("s:NetrwForceChgDir")
5783endfun
5784
5785" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005786" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005787" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5788" expr : this is the expression to follow the directory. Will use s:ComposePath()
5789" pare =1: remove the current directory from the resulting glob() filelist
5790" =0: leave the current directory in the resulting glob() filelist
5791fun! s:NetrwGlob(direntry,expr,pare)
5792" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005793 if netrw#CheckIfRemote()
5794 keepalt 1sp
5795 keepalt enew
5796 let keep_liststyle = w:netrw_liststyle
5797 let w:netrw_liststyle = s:THINLIST
5798 if s:NetrwRemoteListing() == 0
5799 keepj keepalt %s@/@@
5800 let filelist= getline(1,$)
5801 q!
5802 else
5803 " remote listing error -- leave treedict unchanged
5804 let filelist= w:netrw_treedict[a:direntry]
5805 endif
5806 let w:netrw_liststyle= keep_liststyle
5807 else
Christian Brabandt14879472024-06-13 21:25:35 +02005808 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005809 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005810 " escape [ so it is not detected as wildcard character, see :h wildcard
5811 let path= substitute(path, '[', '[[]', 'g')
5812 endif
5813 if v:version > 704 || (v:version == 704 && has("patch656"))
5814 let filelist= glob(path,0,1,1)
5815 else
5816 let filelist= glob(path,0,1)
5817 endif
5818 if a:pare
5819 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5820 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005821 endif
5822" call Dret("s:NetrwGlob ".string(filelist))
5823 return filelist
5824endfun
5825
5826" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005827" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5828fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005829" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005830 if a:newfile =~ '[/@*=|\\]$'
5831 let newfile= substitute(a:newfile,'.$','','')
5832 else
5833 let newfile= a:newfile
5834 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005835 if a:islocal
5836 call s:NetrwBrowseChgDir(a:islocal,newfile)
5837 else
5838 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5839 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005840" call Dret("s:NetrwForceFile")
5841endfun
5842
5843" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005844" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5845" and switches the hiding mode. The actual hiding is done by
5846" s:NetrwListHide().
5847" g:netrw_hide= 0: show all
5848" 1: show not-hidden files
5849" 2: show hidden files only
5850fun! s:NetrwHide(islocal)
5851" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005852 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005853 let svpos= winsaveview()
5854" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005855
5856 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005857" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5858" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859
5860 " hide the files in the markfile list
5861 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005862" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5864 " remove fname from hiding list
5865 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5866 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5867 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 else
5870 " append fname to hiding list
5871 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5872 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5873 else
5874 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5875 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005876" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877 endif
5878 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005879 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880 let g:netrw_hide= 1
5881
5882 else
5883
5884 " switch between show-all/show-not-hidden/show-hidden
5885 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005886 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005888 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005889 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005890" call Dret("NetrwHide")
5891 return
5892 endif
5893 endif
5894
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005895 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005896" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5897 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005898 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005899" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005900endfun
5901
5902" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005903" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5904fun! s:NetrwHideEdit(islocal)
5905" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5906
5907 let ykeep= @@
5908 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005909 let svpos= winsaveview()
5910" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005911
5912 " get new hiding list from user
5913 call inputsave()
5914 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5915 call inputrestore()
5916 let g:netrw_list_hide= newhide
5917" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5918
5919 " refresh the listing
5920 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5921
5922 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005923" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5924 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005925 let @@= ykeep
5926
5927" call Dret("NetrwHideEdit")
5928endfun
5929
5930" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931" s:NetrwHidden: invoked by "gh" {{{2
5932fun! s:NetrwHidden(islocal)
5933" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005934 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005935 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005937" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938
5939 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005940 " remove .file pattern from hiding list
5941" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005942 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005943 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005944" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5946 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005947" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5949 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005950 if g:netrw_list_hide =~ '^,'
5951 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5952 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953
5954 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005955 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005956" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5957 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005958 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959" call Dret("s:NetrwHidden")
5960endfun
5961
5962" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005963" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5964fun! s:NetrwHome()
5965 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005966 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005967 else
5968 " go to vim plugin home
5969 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005970 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005971 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005972 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005973 let home= basehome."/.vim"
5974 break
5975 endif
5976 endfor
5977 if home == ""
5978 " just pick the first directory
5979 let home= substitute(&rtp,',.*$','','')
5980 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005981 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005982 let home= substitute(home,'/','\\','g')
5983 endif
5984 endif
5985 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005986 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005987" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005989" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005990 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005991 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005992" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005993 call mkdir(home)
5994 endif
5995 endif
5996 let g:netrw_home= home
5997 return home
5998endfun
5999
6000" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006001" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6002fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006003 if exists("s:netrwdrag")
6004 return
6005 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006006 if &ft != "netrw"
6007 return
6008 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006009" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006010
Bram Moolenaar97d62492012-11-15 21:28:22 +01006011 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006012 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006013 while getchar(0) != 0
6014 "clear the input stream
6015 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006016 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006017 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018 let mouse_lnum = v:mouse_lnum
6019 let wlastline = line('w$')
6020 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006021" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6022" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006023 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6024 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006025 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006026" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6027 return
6028 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006029 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006030 " 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 +01006031 " without this test when its disabled.
6032 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006033" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006034 if v:mouse_col > virtcol('.')
6035 let @@= ykeep
6036" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6037 return
6038 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006039
Bram Moolenaar446cb832008-06-24 21:56:24 +00006040 if a:islocal
6041 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006042 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006043 endif
6044 else
6045 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006046 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006047 endif
6048 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006049 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006050" call Dret("s:NetrwLeftmouse")
6051endfun
6052
6053" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006054" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6055fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006056 if &ft != "netrw"
6057 return
6058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006059" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6060 call s:NetrwMarkFileTgt(a:islocal)
6061" call Dret("s:NetrwCLeftmouse")
6062endfun
6063
6064" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006065" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6066" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006067" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068" a:islocal=2 : <c-r> used, remote
6069" a:islocal=3 : <c-r> used, local
6070fun! s:NetrwServerEdit(islocal,fname)
6071" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6072 let islocal = a:islocal%2 " =0: remote =1: local
6073 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006078 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006079" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006080 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006081 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006082 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6083 unlet s:netrw_browse_split_{winnr()}
6084 endif
6085 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6086" call Dret("s:NetrwServerEdit")
6087 return
6088 endif
6089
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006092" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093
6094 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006095" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006096 let srvrname = g:netrw_browse_split[0]
6097 let tabnum = g:netrw_browse_split[1]
6098 let winnum = g:netrw_browse_split[2]
6099
6100 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102
6103 if !ctrlr
6104 " user must have closed the server window and the user did not use <c-r>, but
6105 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006107 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006108 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006109 endif
6110 let g:netrw_browse_split= 0
6111 if exists("s:netrw_browse_split_".winnr())
6112 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6113 endif
6114 call s:NetrwBrowseChgDir(islocal,a:fname)
6115" call Dret("s:NetrwServerEdit")
6116 return
6117
6118 elseif has("win32") && executable("start")
6119 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121 call system("start gvim --servername ".srvrname)
6122
6123 else
6124 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126 call system("gvim --servername ".srvrname)
6127 endif
6128 endif
6129
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6132 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006133 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006134
6135 else
6136
6137 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6138
6139 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006140" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006141 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006142 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006143 endif
6144 let g:netrw_browse_split= 0
6145 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6146" call Dret("s:NetrwServerEdit")
6147 return
6148
6149 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006150" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 if has("win32") && executable("start")
6152 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006153" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006154 call system("start gvim --servername ".g:netrw_servername)
6155 else
6156 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006157" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006158 call system("gvim --servername ".g:netrw_servername)
6159 endif
6160 endif
6161 endif
6162
6163 while 1
6164 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006165" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6166 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006167 break
6168 catch /^Vim\%((\a\+)\)\=:E241/
6169 sleep 200m
6170 endtry
6171 endwhile
6172
6173 if exists("g:netrw_browse_split")
6174 if type(g:netrw_browse_split) != 3
6175 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6176 endif
6177 unlet g:netrw_browse_split
6178 endif
6179 let g:netrw_browse_split= [g:netrw_servername,1,1]
6180 endif
6181
6182 else
6183 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6184 endif
6185
6186" call Dret("s:NetrwServerEdit")
6187endfun
6188
6189" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006190" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6191fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006192 if &ft != "netrw"
6193 return
6194 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006195" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006196
Bram Moolenaar8d043172014-01-23 14:24:41 +01006197 let s:ngw= s:NetrwGetWord()
6198 call s:NetrwMarkFile(a:islocal,s:ngw)
6199
6200" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006201endfun
6202
6203" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006204" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6205" Used to mark multiple files.
6206fun! s:NetrwSLeftdrag(islocal)
6207" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6208 if !exists("s:netrwdrag")
6209 let s:netrwdrag = winnr()
6210 if a:islocal
6211 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006212 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006213 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006214 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006215 endif
6216 let ngw = s:NetrwGetWord()
6217 if !exists("s:ngw") || s:ngw != ngw
6218 call s:NetrwMarkFile(a:islocal,ngw)
6219 endif
6220 let s:ngw= ngw
6221" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6222endfun
6223
6224" ---------------------------------------------------------------------
6225" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6226fun! s:NetrwSLeftrelease(islocal)
6227" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6228 if exists("s:netrwdrag")
6229 nunmap <s-leftrelease>
6230 let ngw = s:NetrwGetWord()
6231 if !exists("s:ngw") || s:ngw != ngw
6232 call s:NetrwMarkFile(a:islocal,ngw)
6233 endif
6234 if exists("s:ngw")
6235 unlet s:ngw
6236 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006237 unlet s:netrwdrag
6238 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006239" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006240endfun
6241
6242" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006243" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6244" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006245fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006246" 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 +02006247" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006248 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006249
6250 " 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 +02006251 " How-it-works: take the hiding command, convert it into a range.
6252 " Duplicate characters don't matter.
6253 " Remove all such characters from the '/~@#...890' string.
6254 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006255" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006257 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006258" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006259
6260 while listhide != ""
6261 if listhide =~ ','
6262 let hide = substitute(listhide,',.*$','','e')
6263 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6264 else
6265 let hide = listhide
6266 let listhide = ""
6267 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006268" 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 +01006269 if g:netrw_sort_by =~ '^[ts]'
6270 if hide =~ '^\^'
6271" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6272 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6273 elseif hide =~ '^\\(\^'
6274 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6275 endif
6276" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6277 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006278
6279 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006280" 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 +00006281 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006282" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006283 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006286 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006287 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290
Bram Moolenaar446cb832008-06-24 21:56:24 +00006291 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006295" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296 endif
6297
Bram Moolenaaradc21822011-04-01 18:03:16 +02006298 " remove any blank lines that have somehow remained.
6299 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006300 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006301
Bram Moolenaar97d62492012-11-15 21:28:22 +01006302 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304endfun
6305
6306" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006308" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006310" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006311
Bram Moolenaar97d62492012-11-15 21:28:22 +01006312 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313 " get name of new directory from user. A bare <CR> will skip.
6314 " if its currently a directory, also request will be skipped, but with
6315 " a message.
6316 call inputsave()
6317 let newdirname= input("Please give directory name: ")
6318 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006319" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006320
6321 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006322 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006323" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 return
6325 endif
6326
6327 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006328" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329
6330 " Local mkdir:
6331 " sanity checks
6332 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006333" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6334 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006336 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006338 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006339" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 return
6341 endif
6342 if s:FileReadable(fullnewdir)
6343 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006344 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006346 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006347" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006348 return
6349 endif
6350
6351 " requested new local directory is neither a pre-existing file or
6352 " directory, so make it!
6353 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006354 if has("unix")
6355 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6356 else
6357 call mkdir(fullnewdir,"p")
6358 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006359 else
6360 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006361 if s:NetrwLcd(b:netrw_curdir)
6362" call Dret("s:NetrwMakeDir : lcd failure")
6363 return
6364 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006365" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006366 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006367 if v:shell_error != 0
6368 let @@= ykeep
6369 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006370" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006371 return
6372 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006373 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006374" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006375 if s:NetrwLcd(netrw_origdir)
6376" call Dret("s:NetrwBrowse : lcd failure")
6377 return
6378 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379 endif
6380 endif
6381
6382 if v:shell_error == 0
6383 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006384" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006385 let svpos= winsaveview()
6386" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006387 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006388" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6389 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006390 elseif !exists("g:netrw_quiet")
6391 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6392 endif
6393" redraw!
6394
6395 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006396 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006397" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6399 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006400 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401 if v:shell_error == 0
6402 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006403 let svpos= winsaveview()
6404" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006405 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006406" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6407 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006408 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006409 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006410 endif
6411" redraw!
6412
6413 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006414 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006415 let svpos= winsaveview()
6416" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006417" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 let remotepath= b:netrw_fname
6421 else
6422 let remotepath= ""
6423 endif
6424 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006425 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6427 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006428
Bram Moolenaar446cb832008-06-24 21:56:24 +00006429 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006430 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006431 let svpos= winsaveview()
6432" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006433" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006434 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006435" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006436 let remotepath= b:netrw_fname
6437 else
6438 let remotepath= ""
6439 endif
6440 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006441 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006442" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6443 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006444 endif
6445
Bram Moolenaar97d62492012-11-15 21:28:22 +01006446 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006447" call Dret("s:NetrwMakeDir")
6448endfun
6449
6450" ---------------------------------------------------------------------
6451" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6452fun! s:TreeSqueezeDir(islocal)
6453" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6454 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6455 " its a tree-listing style
6456 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006457 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006458 let depth = strchars(substitute(curdepth,' ','','g'))
6459 let srch = -1
6460" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6461" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006462" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006463" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6464 if depth >= 2
6465 NetrwKeepj norm! 0
6466 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6467 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6468" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6469" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6470 elseif depth == 1
6471 NetrwKeepj norm! 0
6472 let treedepthchr= substitute(s:treedepthstring,' ','','')
6473 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6474" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6475 endif
6476 if srch > 0
6477" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6478 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6479 exe srch
6480 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006481 endif
6482" call Dret("s:TreeSqueezeDir")
6483endfun
6484
6485" ---------------------------------------------------------------------
6486" s:NetrwMaps: {{{2
6487fun! s:NetrwMaps(islocal)
6488" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6489
Bram Moolenaar85850f32019-07-19 22:05:51 +02006490 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006492" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006493 if !hasmapto("<Plug>NetrwReturn")
6494 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006495" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6497 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6500 endif
6501 endif
6502 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006504 endif
6505
Bram Moolenaar85850f32019-07-19 22:05:51 +02006506 " generate default <Plug> maps {{{3
6507 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006508 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006509 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6510 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6511 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6512 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6513 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6514 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6515 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6516 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6517 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6518 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6519" ---------------------------------------------------------------------
6520" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6521" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6522" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6523" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6524" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6525" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6526" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6527" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6528" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6529" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6530" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6531" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6532" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6533" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6534" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6535" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6536" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6537" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6538" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6539" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6540" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6541" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6542" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6543" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6544" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6545" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6546" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6547" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6548" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6549" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6550" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6551" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6552" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6553" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6554" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6555" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6556" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6557" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6558" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6559" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6560" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6561" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6562" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6563" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6564" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6565" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6566" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6567
Bram Moolenaara6878372014-03-22 21:02:50 +01006568 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006569" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006570 " local normal-mode maps {{{3
6571 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6577 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6578 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6579 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6580 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6581 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6582" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006583 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6584 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6585 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006586 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006587 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006588 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6589 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6591 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006592 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6593 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6594 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6598 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6599 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6602 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6604 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006606 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6609 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6610 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6611 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006612 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006613 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6615 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6617 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6618 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006621 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6622 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6626 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6627 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006628 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6629 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006630
6631 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 if !hasmapto('<Plug>NetrwHideEdit')
6633 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006634 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006635 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006636 if !hasmapto('<Plug>NetrwRefresh')
6637 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006638 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006639 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 if s:didstarstar || !mapcheck("<s-down>","n")
6641 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 endif
6643 if s:didstarstar || !mapcheck("<s-up>","n")
6644 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 if !hasmapto('<Plug>NetrwTreeSqueeze')
6647 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006648 endif
6649 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006650 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6651 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006652 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6653 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6654 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6655 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6656 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6657 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6658 imap <buffer> <leftmouse> <Plug>ILeftmouse
6659 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006660 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6661 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6662 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6663 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6664 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006665 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006666 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6667 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006669 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6670 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6671 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6672 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6673 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6674 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6675 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6677
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678 " support user-specified maps
6679 call netrw#UserMaps(1)
6680
Bram Moolenaar85850f32019-07-19 22:05:51 +02006681 else
6682 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006684 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006685 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6691 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6692 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6693 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6694 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6695 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6696" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006697 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6698 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6699 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6701 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6702 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6704 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006705 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006706 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006707 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6711 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6712 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006718 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006719 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006720 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6723 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6724 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006725 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6726 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6728 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006730 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6731 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006732 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006733 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006734 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6736 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6737 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6738 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6739 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6740 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6741 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6742 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006743 if !hasmapto('<Plug>NetrwHideEdit')
6744 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006745 endif
6746 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6747 if !hasmapto('<Plug>NetrwRefresh')
6748 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006749 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006750 if !hasmapto('<Plug>NetrwTreeSqueeze')
6751 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006752 endif
6753 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006754
6755 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006756 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006757
6758 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6759 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006761 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006763 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006764 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006765 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006767 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006769 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6771 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6772 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006774 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006775 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006777 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6780 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6781 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6782 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6783 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6784 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006785 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006786
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006787 " support user-specified maps
6788 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006789 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006790
6791" call Dret("s:NetrwMaps")
6792endfun
6793
6794" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006795" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006796" If -buffer, the command is only available from within netrw buffers
6797" Otherwise, the command is available from any window, so long as netrw
6798" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006799fun! s:NetrwCommands(islocal)
6800" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6801
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006802 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6803 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006804 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 +01006805 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006806 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006807 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006808 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006809 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006810 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006811
6812" call Dret("s:NetrwCommands")
6813endfun
6814
6815" ---------------------------------------------------------------------
6816" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6817" glob()ing only works with local files
6818fun! s:NetrwMarkFiles(islocal,...)
6819" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820 let curdir = s:NetrwGetCurdir(a:islocal)
6821 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006822 while i <= a:0
6823 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006824 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006825 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006827 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006828 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006829 else
6830 let mffiles= [a:{i}]
6831 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006833 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006834" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006835 call s:NetrwMarkFile(a:islocal,mffile)
6836 endfor
6837 let i= i + 1
6838 endwhile
6839" call Dret("s:NetrwMarkFiles")
6840endfun
6841
6842" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006843" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006844fun! s:NetrwMarkTarget(...)
6845" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6846 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006847 let curdir = s:NetrwGetCurdir(1)
6848 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6851 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006852 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006855 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6856 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006857 let svpos = winsaveview()
6858" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006859 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006860" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6861 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006862" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006863endfun
6864
6865" ---------------------------------------------------------------------
6866" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6867" mark and unmark files. If a markfile list exists,
6868" then the rename and delete functions will use it instead
6869" of whatever may happen to be under the cursor at that
6870" moment. When the mouse and gui are available,
6871" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006872"
6873" Creates two lists
6874" s:netrwmarkfilelist -- holds complete paths to all marked files
6875" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6876"
6877" Creates a marked file match string
6878" s:netrwmarfilemtch_# -- used with 2match to display marked files
6879"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006880" Creates a buffer version of islocal
6881" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006882fun! s:NetrwMarkFile(islocal,fname)
6883" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006884" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006885
6886 " sanity check
6887 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006888" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006889 return
6890 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006891 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006892
Bram Moolenaar97d62492012-11-15 21:28:22 +01006893 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006894 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006895 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006896 if a:fname =~ '\a$'
6897 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6898 else
6899 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6900 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006901
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006902 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006903 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006904" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6905" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6906" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006907 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908
6909 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006910 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006913 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914
6915 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006916 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006917" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6919 if s:netrwmarkfilelist_{curbufnr} == []
6920 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006921" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 call s:NetrwUnmarkList(curbufnr,curdir)
6923 else
6924 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006925" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006926 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006927 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006928 for fname in s:netrwmarkfilelist_{curbufnr}
6929 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006930 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006931 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006932 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 endif
6934 let first= 0
6935 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006937 endif
6938 endif
6939
6940 else
6941 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006944" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006945 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006946 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6947" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948
6949 " build initial markfile matching pattern
6950 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006951 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006953 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006955" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006956 endif
6957
6958 " handle global markfilelist
6959 if exists("s:netrwmarkfilelist")
6960 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6961 if index(s:netrwmarkfilelist,dname) == -1
6962 " append new filename to global markfilelist
6963 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006964" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 else
6966 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006967" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6968" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006970" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006972" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973 unlet s:netrwmarkfilelist
6974 endif
6975 endif
6976 else
6977 " initialize new global-directory markfilelist
6978 let s:netrwmarkfilelist= []
6979 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006980" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006981 endif
6982
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006983 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006984 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6985 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6986" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6987 if exists("g:did_drchip_netrwlist_syntax")
6988 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6989 endif
6990 else
6991" " call Decho("2match none",'~'.expand("<slnum>"))
6992 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006994 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006995 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006996" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6997" 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 +00006998endfun
6999
7000" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007001" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7002" mA: move the argument list to marked file list (tomflist=1)
7003" Uses the global marked file list
7004fun! s:NetrwMarkFileArgList(islocal,tomflist)
7005" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7006
7007 let svpos = winsaveview()
7008" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7009 let curdir = s:NetrwGetCurdir(a:islocal)
7010 let curbufnr = bufnr("%")
7011
7012 if a:tomflist
7013 " mA: move argument list to marked file list
7014 while argc()
7015 let fname= argv(0)
7016" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7017 exe "argdel ".fnameescape(fname)
7018 call s:NetrwMarkFile(a:islocal,fname)
7019 endwhile
7020
7021 else
7022 " ma: move marked file list to argument list
7023 if exists("s:netrwmarkfilelist")
7024
7025 " for every filename in the marked list
7026 for fname in s:netrwmarkfilelist
7027" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7028 exe "argadd ".fnameescape(fname)
7029 endfor " for every file in the marked list
7030
7031 " unmark list and refresh
7032 call s:NetrwUnmarkList(curbufnr,curdir)
7033 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7034" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7035 NetrwKeepj call winrestview(svpos)
7036 endif
7037 endif
7038
7039" call Dret("s:NetrwMarkFileArgList")
7040endfun
7041
7042" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007043" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7044" compress/decompress files using the programs
7045" in g:netrw_compress and g:netrw_uncompress,
7046" using g:netrw_compress_suffix to know which to
7047" do. By default:
7048" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007049" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007050fun! s:NetrwMarkFileCompress(islocal)
7051" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007052 let svpos = winsaveview()
7053" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007054 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007055 let curbufnr = bufnr("%")
7056
Bram Moolenaarff034192013-04-24 18:51:19 +02007057 " sanity check
7058 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007059 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007060" call Dret("s:NetrwMarkFileCompress")
7061 return
7062 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007063" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007064
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007066
7067 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007068 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007069 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007071 if exists("g:netrw_decompress['".sfx."']")
7072 " fname has a suffix indicating that its compressed; apply associated decompression routine
7073 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007074" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007075 let exe= netrw#WinPath(exe)
7076 if a:islocal
7077 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007078 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007079 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007080 call system(exe." ".fname)
7081 if v:shell_error
7082 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007083 endif
7084 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007085 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7086 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007087 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007088
Bram Moolenaarff034192013-04-24 18:51:19 +02007089 endif
7090 unlet sfx
7091
Bram Moolenaar446cb832008-06-24 21:56:24 +00007092 if exists("exe")
7093 unlet exe
7094 elseif a:islocal
7095 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007096 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007097 if v:shell_error
7098 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7099 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007100 else
7101 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007104 endfor " for every file in the marked list
7105
Bram Moolenaar446cb832008-06-24 21:56:24 +00007106 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007107 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007108" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7109 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007110 endif
7111" call Dret("s:NetrwMarkFileCompress")
7112endfun
7113
7114" ---------------------------------------------------------------------
7115" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7116" If no marked files, then set up directory as the
7117" target. Currently does not support copying entire
7118" directories. Uses the local-buffer marked file list.
7119" Returns 1=success (used by NetrwMarkFileMove())
7120" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007121fun! s:NetrwMarkFileCopy(islocal,...)
7122" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7123
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007124 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007125 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007126 if b:netrw_curdir !~ '/$'
7127 if !exists("b:netrw_curdir")
7128 let b:netrw_curdir= curdir
7129 endif
7130 let b:netrw_curdir= b:netrw_curdir."/"
7131 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132
Bram Moolenaarff034192013-04-24 18:51:19 +02007133 " sanity check
7134 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007135 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007136" call Dret("s:NetrwMarkFileCopy")
7137 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007139" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007140
Bram Moolenaar446cb832008-06-24 21:56:24 +00007141 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007142 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007143" call Dret("s:NetrwMarkFileCopy 0")
7144 return 0
7145 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007146" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007147
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007148 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007149 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007150" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007151 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007152 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7153" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7154 return
7155 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007156
7157 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007158 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7160 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007162 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007163 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7164 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007165" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007166 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007167 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007168 let oldname = a:1
7169 else
7170 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007171" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007172 let s:recursive= 1
7173 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7174 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7175 if ret == 0
7176 break
7177 endif
7178 endfor
7179 unlet s:recursive
7180 call s:NetrwUnmarkList(curbufnr,curdir)
7181" call Dret("s:NetrwMarkFileCopy ".ret)
7182 return ret
7183 endif
7184
7185 call inputsave()
7186 let newname= input("Copy ".oldname." to : ",oldname,"file")
7187 call inputrestore()
7188 if newname == ""
7189" call Dret("s:NetrwMarkFileCopy 0")
7190 return 0
7191 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007192 let args= s:ShellEscape(oldname)
7193 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007194 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007195 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7196 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007197 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007198 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007199 let args= substitute(args,'/','\\','g')
7200 let tgt = substitute(tgt, '/','\\','g')
7201 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007202 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7203 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7204 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7205 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7206" call Decho("args <".args.">",'~'.expand("<slnum>"))
7207" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007208 if isdirectory(s:NetrwFile(args))
7209" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007210 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007211" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007212 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007213 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7214 " contents to a target. One must append the source directory name to the target to get xcopy to
7215 " do the right thing.
7216 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007218 endif
7219 else
7220 let copycmd= g:netrw_localcopycmd
7221 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007222 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007223 let copycmd = substitute(copycmd,'\s.*$','','')
7224 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007225 let copycmd = netrw#WinPath(copycmd).copycmdargs
7226 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007227 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007228 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007229" call Decho("args <".args.">",'~'.expand("<slnum>"))
7230" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7231" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7232" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007233 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007234 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007235 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007236 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 +01007237 else
7238 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7239 endif
7240" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007241 return 0
7242 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007243
7244 elseif a:islocal && !s:netrwmftgt_islocal
7245 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007246" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007248
7249 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007250 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007251" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007252 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253
7254 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007255 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007256" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007257 let curdir = getcwd()
7258 let tmpdir = s:GetTempfile("")
7259 if tmpdir !~ '/'
7260 let tmpdir= curdir."/".tmpdir
7261 endif
7262 if exists("*mkdir")
7263 call mkdir(tmpdir)
7264 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007265 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007266 if v:shell_error != 0
7267 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 +01007268" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007269 return
7270 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007272 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007273 if s:NetrwLcd(tmpdir)
7274" call Dret("s:NetrwMarkFileCopy : lcd failure")
7275 return
7276 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007277 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007278 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007279 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280 if getcwd() == tmpdir
7281 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007282 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007284 if s:NetrwLcd(curdir)
7285" call Dret("s:NetrwMarkFileCopy : lcd failure")
7286 return
7287 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007288 if delete(tmpdir,"d")
7289 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007290 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007292 if s:NetrwLcd(curdir)
7293" call Dret("s:NetrwMarkFileCopy : lcd failure")
7294 return
7295 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007296 endif
7297 endif
7298 endif
7299
7300 " -------
7301 " cleanup
7302 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007303" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007304 " remove markings from local buffer
7305 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007306" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7307" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7308" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7309" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7310" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7311" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7312 if exists("s:recursive")
7313" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7314 else
7315" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007316 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007317 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007318 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007319 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007320 else
7321 " refresh local and targets for fast browsing
7322 if !exists("s:recursive")
7323 " remove markings from local buffer
7324" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7325 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7326 endif
7327
7328 " refresh buffers
7329 if s:netrwmftgt_islocal
7330" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7331 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7332 endif
7333 if a:islocal && s:netrwmftgt != curdir
7334" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7335 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7336 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007337 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007338
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339" call Dret("s:NetrwMarkFileCopy 1")
7340 return 1
7341endfun
7342
7343" ---------------------------------------------------------------------
7344" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7345" invoke vim's diff mode on the marked files.
7346" Either two or three files can be so handled.
7347" Uses the global marked file list.
7348fun! s:NetrwMarkFileDiff(islocal)
7349" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7350 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351
Bram Moolenaarff034192013-04-24 18:51:19 +02007352 " sanity check
7353 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007354 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007355" call Dret("s:NetrwMarkFileDiff")
7356 return
7357 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358 let curdir= s:NetrwGetCurdir(a:islocal)
7359" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007360
Bram Moolenaara6878372014-03-22 21:02:50 +01007361 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363 for fname in s:netrwmarkfilelist
7364 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007366" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007367 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007368 diffthis
7369 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007370 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007371" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007372 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007373 diffthis
7374 else
7375 break
7376 endif
7377 endfor
7378 call s:NetrwUnmarkList(curbufnr,curdir)
7379 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007380
Bram Moolenaar446cb832008-06-24 21:56:24 +00007381" call Dret("s:NetrwMarkFileDiff")
7382endfun
7383
7384" ---------------------------------------------------------------------
7385" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7386" Uses global markfilelist
7387fun! s:NetrwMarkFileEdit(islocal)
7388" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7389
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007392
7393 " sanity check
7394 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007396" call Dret("s:NetrwMarkFileEdit")
7397 return
7398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007399" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007400
Bram Moolenaar446cb832008-06-24 21:56:24 +00007401 if exists("s:netrwmarkfilelist_{curbufnr}")
7402 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007403 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007404 " unmark markedfile list
7405" call s:NetrwUnmarkList(curbufnr,curdir)
7406 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007407" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007408 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007409 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007410 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007411
Bram Moolenaar446cb832008-06-24 21:56:24 +00007412" call Dret("s:NetrwMarkFileEdit")
7413endfun
7414
7415" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007416" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007417fun! s:NetrwMarkFileQFEL(islocal,qfel)
7418" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7419 call s:NetrwUnmarkAll()
7420 let curbufnr= bufnr("%")
7421
7422 if !empty(a:qfel)
7423 for entry in a:qfel
7424 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007426 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007427" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007428 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7429 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7430 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7431 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007432" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007433 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7434 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007436 endif
7437 endfor
7438 echo "(use me to edit marked files)"
7439 else
7440 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7441 endif
7442
7443" call Dret("s:NetrwMarkFileQFEL")
7444endfun
7445
7446" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007447" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7448" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7449" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7450fun! s:NetrwMarkFileExe(islocal,enbloc)
7451" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007452 let svpos = winsaveview()
7453" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007454 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007455 let curbufnr = bufnr("%")
7456
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007457 if a:enbloc == 0
7458 " individually apply command to files, one at a time
7459 " sanity check
7460 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7461 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7462" call Dret("s:NetrwMarkFileExe")
7463 return
7464 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007465" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007466
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 if exists("s:netrwmarkfilelist_{curbufnr}")
7468 " get the command
7469 call inputsave()
7470 let cmd= input("Enter command: ","","file")
7471 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007472" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007473 if cmd == ""
7474" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7475 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007477
7478 " apply command to marked files, individually. Substitute: filename -> %
7479 " If no %, then append a space and the filename to the command
7480 for fname in s:netrwmarkfilelist_{curbufnr}
7481 if a:islocal
7482 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007483 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007484 endif
7485 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007486 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007487 endif
7488 if cmd =~ '%'
7489 let xcmd= substitute(cmd,'%',fname,'g')
7490 else
7491 let xcmd= cmd.' '.fname
7492 endif
7493 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007494" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 let ret= system(xcmd)
7496 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007497" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007498 let ret= s:RemoteSystem(xcmd)
7499 endif
7500 if v:shell_error < 0
7501 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7502 break
7503 else
yasudac75dad02024-08-22 21:06:32 +02007504 if ret !=# ''
7505 echo "\n"
7506 " skip trailing new line
7507 echo ret[0:-2]
7508 else
7509 echo ret
7510 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 endif
7512 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513
7514 " unmark marked file list
7515 call s:NetrwUnmarkList(curbufnr,curdir)
7516
7517 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007518 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007519" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7520 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007521 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007522 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007523 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524
7525 else " apply command to global list of files, en bloc
7526
7527 call inputsave()
7528 let cmd= input("Enter command: ","","file")
7529 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007530" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007531 if cmd == ""
7532" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7533 return
7534 endif
7535 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007536 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007537 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007538 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007539 endif
7540 if a:islocal
7541 call system(cmd)
7542 if v:shell_error < 0
7543 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7544 endif
7545 else
7546 let ret= s:RemoteSystem(cmd)
7547 endif
7548 call s:NetrwUnmarkAll()
7549
7550 " refresh the listing
7551 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007552" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7553 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007554
7555 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007556
Bram Moolenaar446cb832008-06-24 21:56:24 +00007557" call Dret("s:NetrwMarkFileExe")
7558endfun
7559
7560" ---------------------------------------------------------------------
7561" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7562" as the marked file(s) (toggles suffix presence)
7563" Uses the local marked file list.
7564fun! s:NetrwMarkHideSfx(islocal)
7565" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007566 let svpos = winsaveview()
7567" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007568 let curbufnr = bufnr("%")
7569
7570 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7571 if exists("s:netrwmarkfilelist_{curbufnr}")
7572
7573 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007574" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007575 " construct suffix pattern
7576 if fname =~ '\.'
7577 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7578 else
7579 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7580 endif
7581 " determine if its in the hiding list or not
7582 let inhidelist= 0
7583 if g:netrw_list_hide != ""
7584 let itemnum = 0
7585 let hidelist= split(g:netrw_list_hide,',')
7586 for hidepat in hidelist
7587 if sfxpat == hidepat
7588 let inhidelist= 1
7589 break
7590 endif
7591 let itemnum= itemnum + 1
7592 endfor
7593 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007594" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007595 if inhidelist
7596 " remove sfxpat from list
7597 call remove(hidelist,itemnum)
7598 let g:netrw_list_hide= join(hidelist,",")
7599 elseif g:netrw_list_hide != ""
7600 " append sfxpat to non-empty list
7601 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7602 else
7603 " set hiding list to sfxpat
7604 let g:netrw_list_hide= sfxpat
7605 endif
7606 endfor
7607
7608 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007609 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007610" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7611 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007614 endif
7615
7616" call Dret("s:NetrwMarkHideSfx")
7617endfun
7618
7619" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007620" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007621" Uses the local marked-file list.
7622fun! s:NetrwMarkFileVimCmd(islocal)
7623" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007624 let svpos = winsaveview()
7625" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007626 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007627 let curbufnr = bufnr("%")
7628
Bram Moolenaarff034192013-04-24 18:51:19 +02007629 " sanity check
7630 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007631 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007632" call Dret("s:NetrwMarkFileVimCmd")
7633 return
7634 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007636
Bram Moolenaar15146672011-10-20 22:22:38 +02007637 if exists("s:netrwmarkfilelist_{curbufnr}")
7638 " get the command
7639 call inputsave()
7640 let cmd= input("Enter vim command: ","","file")
7641 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007642" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007643 if cmd == ""
7644" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7645 return
7646 endif
7647
7648 " apply command to marked files. Substitute: filename -> %
7649 " If no %, then append a space and the filename to the command
7650 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007651" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007652 if a:islocal
7653 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007654 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007655" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007656 exe cmd
7657 exe "sil! keepalt wq!"
7658 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007659" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007660 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 endif
7662 endfor
7663
7664 " unmark marked file list
7665 call s:NetrwUnmarkList(curbufnr,curdir)
7666
7667 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007668 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007669" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7670 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007671 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007672 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674
Bram Moolenaar15146672011-10-20 22:22:38 +02007675" call Dret("s:NetrwMarkFileVimCmd")
7676endfun
7677
7678" ---------------------------------------------------------------------
7679" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7680" as the marked file(s) (toggles suffix presence)
7681" Uses the local marked file list.
7682fun! s:NetrwMarkHideSfx(islocal)
7683" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007684 let svpos = winsaveview()
7685" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007686 let curbufnr = bufnr("%")
7687
7688 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7689 if exists("s:netrwmarkfilelist_{curbufnr}")
7690
7691 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007692" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007693 " construct suffix pattern
7694 if fname =~ '\.'
7695 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7696 else
7697 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7698 endif
7699 " determine if its in the hiding list or not
7700 let inhidelist= 0
7701 if g:netrw_list_hide != ""
7702 let itemnum = 0
7703 let hidelist= split(g:netrw_list_hide,',')
7704 for hidepat in hidelist
7705 if sfxpat == hidepat
7706 let inhidelist= 1
7707 break
7708 endif
7709 let itemnum= itemnum + 1
7710 endfor
7711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007712" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007713 if inhidelist
7714 " remove sfxpat from list
7715 call remove(hidelist,itemnum)
7716 let g:netrw_list_hide= join(hidelist,",")
7717 elseif g:netrw_list_hide != ""
7718 " append sfxpat to non-empty list
7719 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7720 else
7721 " set hiding list to sfxpat
7722 let g:netrw_list_hide= sfxpat
7723 endif
7724 endfor
7725
7726 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007727 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007728" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7729 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007730 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007731 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007732 endif
7733
7734" call Dret("s:NetrwMarkHideSfx")
7735endfun
7736
7737" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007738" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7739" Uses the global markfilelist
7740fun! s:NetrwMarkFileGrep(islocal)
7741" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007742 let svpos = winsaveview()
7743" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007745 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746
7747 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007748" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007749 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007750" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007751 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007753" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007754 let netrwmarkfilelist= "*"
7755 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007756
Bram Moolenaarff034192013-04-24 18:51:19 +02007757 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007758" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007759 call inputsave()
7760 let pat= input("Enter pattern: ","")
7761 call inputrestore()
7762 let patbang = ""
7763 if pat =~ '^!'
7764 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007766 endif
7767 if pat =~ '^\i'
7768 let pat = escape(pat,'/')
7769 let pat = '/'.pat.'/'
7770 else
7771 let nonisi = pat[0]
7772 endif
7773
7774 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007775" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007776 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007777 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007778 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007779 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007780" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7781 return
7782 endtry
7783 echo "(use :cn, :cp to navigate, :Rex to return)"
7784
7785 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007786" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7787 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007788
7789 if exists("nonisi")
7790 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007792 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007793 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007795 endif
7796
7797" call Dret("s:NetrwMarkFileGrep")
7798endfun
7799
7800" ---------------------------------------------------------------------
7801" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7802" uses the global marked file list
7803" s:netrwmfloc= 0: target directory is remote
7804" = 1: target directory is local
7805fun! s:NetrwMarkFileMove(islocal)
7806" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007807 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808 let curbufnr = bufnr("%")
7809
7810 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007811 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007812 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813" call Dret("s:NetrwMarkFileMove")
7814 return
7815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007817
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007819 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007820" call Dret("s:NetrwMarkFileCopy 0")
7821 return 0
7822 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007823" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824
7825 if a:islocal && s:netrwmftgt_islocal
7826 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827" call Decho("move from local to local",'~'.expand("<slnum>"))
7828" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007829 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007830 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7831" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7832 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007833 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007834 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007835" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007836 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007837 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007838" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007839 if g:netrw_localmovecmd =~ '\s'
7840 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7841 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7842 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007845 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007846" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007847 endif
7848 else
7849 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007851 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007852 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007853 if g:netrw_keepdir
7854 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7855 let fname= b:netrw_curdir."/".fname
7856 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007857 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007858 let fname= substitute(fname,'/','\\','g')
7859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007861 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007862 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007863 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007864 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 +01007865 else
7866 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7867 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007868 break
7869 endif
7870 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007871
7872 elseif a:islocal && !s:netrwmftgt_islocal
7873 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007874" call Decho("move from local to remote",'~'.expand("<slnum>"))
7875" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007876 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007877 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007878" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879 for fname in mflist
7880 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7881 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7882 endfor
7883 unlet mflist
7884
7885 elseif !a:islocal && s:netrwmftgt_islocal
7886 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007887" call Decho("move from remote to local",'~'.expand("<slnum>"))
7888" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007890 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007891" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 for fname in mflist
7893 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7894 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7895 endfor
7896 unlet mflist
7897
7898 elseif !a:islocal && !s:netrwmftgt_islocal
7899 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007900" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7901" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007903 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007904" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007905 for fname in mflist
7906 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7907 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7908 endfor
7909 unlet mflist
7910 endif
7911
7912 " -------
7913 " cleanup
7914 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007915" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007916
7917 " remove markings from local buffer
7918 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7919
7920 " refresh buffers
7921 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007922" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007923 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924 endif
7925 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007927 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007928 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007929 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007930" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007931 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007932 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007933
Bram Moolenaar446cb832008-06-24 21:56:24 +00007934" call Dret("s:NetrwMarkFileMove")
7935endfun
7936
7937" ---------------------------------------------------------------------
7938" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7939" using the hardcopy command. Local marked-file list only.
7940fun! s:NetrwMarkFilePrint(islocal)
7941" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7942 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007943
7944 " sanity check
7945 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007946 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007947" call Dret("s:NetrwMarkFilePrint")
7948 return
7949 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7951 let curdir= s:NetrwGetCurdir(a:islocal)
7952
Bram Moolenaar446cb832008-06-24 21:56:24 +00007953 if exists("s:netrwmarkfilelist_{curbufnr}")
7954 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007955 call s:NetrwUnmarkList(curbufnr,curdir)
7956 for fname in netrwmarkfilelist
7957 if a:islocal
7958 if g:netrw_keepdir
7959 let fname= s:ComposePath(curdir,fname)
7960 endif
7961 else
7962 let fname= curdir.fname
7963 endif
7964 1split
7965 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007966" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007967 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007968" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969 hardcopy
7970 q
7971 endfor
7972 2match none
7973 endif
7974" call Dret("s:NetrwMarkFilePrint")
7975endfun
7976
7977" ---------------------------------------------------------------------
7978" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7979" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007980" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007981fun! s:NetrwMarkFileRegexp(islocal)
7982" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7983
7984 " get the regular expression
7985 call inputsave()
7986 let regexp= input("Enter regexp: ","","file")
7987 call inputrestore()
7988
7989 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007991" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007994 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007995 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007996 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007997 else
7998 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007999 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008000 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008001" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008002
8003 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008004 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008005 if fname =~ '^'.fnameescape(curdir)
8006" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8007 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8008 else
8009" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8010 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8011 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008012 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013
8014 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016
8017 " convert displayed listing into a filelist
8018 let eikeep = &ei
8019 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008020 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008021 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008022" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008023 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008024 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008025 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008026 sil NetrwKeepj norm! "ap
8027 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008029 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008030 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008031 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008032 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008033 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008035 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008036 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008038 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8039 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008040 call histdel("/",-1)
8041 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 endif
8043 " convert regexp into the more usual glob-style format
8044 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008046 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008047 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 let filelist= getline(1,line("$"))
8049 q!
8050 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008051 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 endfor
8053 unlet filelist
8054 let @a = areg
8055 let &ei = eikeep
8056 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008057 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058
8059" call Dret("s:NetrwMarkFileRegexp")
8060endfun
8061
8062" ---------------------------------------------------------------------
8063" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8064" Uses the local marked file list.
8065fun! s:NetrwMarkFileSource(islocal)
8066" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8067 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008068
8069 " sanity check
8070 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008071 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008072" call Dret("s:NetrwMarkFileSource")
8073 return
8074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008075" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8076 let curdir= s:NetrwGetCurdir(a:islocal)
8077
Bram Moolenaar446cb832008-06-24 21:56:24 +00008078 if exists("s:netrwmarkfilelist_{curbufnr}")
8079 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008080 call s:NetrwUnmarkList(curbufnr,curdir)
8081 for fname in netrwmarkfilelist
8082 if a:islocal
8083 if g:netrw_keepdir
8084 let fname= s:ComposePath(curdir,fname)
8085 endif
8086 else
8087 let fname= curdir.fname
8088 endif
8089 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008090" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008091 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008092 endfor
8093 2match none
8094 endif
8095" call Dret("s:NetrwMarkFileSource")
8096endfun
8097
8098" ---------------------------------------------------------------------
8099" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8100" Uses the global markfilelist
8101fun! s:NetrwMarkFileTag(islocal)
8102" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008103 let svpos = winsaveview()
8104" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008105 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 let curbufnr = bufnr("%")
8107
Bram Moolenaarff034192013-04-24 18:51:19 +02008108 " sanity check
8109 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008110 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008111" call Dret("s:NetrwMarkFileTag")
8112 return
8113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008114" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008115
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008117" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8118 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 call s:NetrwUnmarkAll()
8120
8121 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008122
8123" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8124 call system(g:netrw_ctags." ".netrwmarkfilelist)
8125 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8127 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008128
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008130 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008131 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 let curdir= b:netrw_curdir
8133 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008134 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008136" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008137 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008138 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 wq!
8140 endif
8141 2match none
8142 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008143" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8144 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008145 endif
8146
8147" call Dret("s:NetrwMarkFileTag")
8148endfun
8149
8150" ---------------------------------------------------------------------
8151" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008152" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008153" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008155" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008156fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008157" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8158 let svpos = winsaveview()
8159" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008160 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008161 let hadtgt = exists("s:netrwmftgt")
8162 if !exists("w:netrw_bannercnt")
8163 let w:netrw_bannercnt= b:netrw_bannercnt
8164 endif
8165
8166 " set up target
8167 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008168" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008169 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8170 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008172 unlet s:netrwmftgt s:netrwmftgt_islocal
8173 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008174 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008175 endif
8176 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008177" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8178 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008179" call Dret("s:NetrwMarkFileTgt : removed target")
8180 return
8181 else
8182 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008184 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185
8186 else
8187 " get word under cursor.
8188 " * If directory, use it for the target.
8189 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008190" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008191 let curword= s:NetrwGetWord()
8192 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008194 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008195" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196 elseif !a:islocal && tgtdir =~ '/$'
8197 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008198" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199 else
8200 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008201" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008202 endif
8203 endif
8204 if a:islocal
8205 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8206 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208 endif
8209 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008210 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8212 endif
8213 let s:netrwmftgt_islocal= a:islocal
8214
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215 " need to do refresh so that the banner will be updated
8216 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008217 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008218" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008219 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008220 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008222 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8224 else
8225 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8226 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008227" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8228 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008229 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008230 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231 endif
8232
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008233" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8234" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008235" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8236endfun
8237
8238" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8240fun! s:NetrwGetCurdir(islocal)
8241" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8242
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008243 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008244 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8245" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8246 elseif !exists("b:netrw_curdir")
8247 let b:netrw_curdir= getcwd()
8248" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8249 endif
8250
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008251" 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 +01008252 if b:netrw_curdir !~ '\<\a\{3,}://'
8253 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008254" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008255 if g:netrw_keepdir == 0
8256 call s:NetrwLcd(curdir)
8257 endif
8258 endif
8259
8260" call Dret("s:NetrwGetCurdir <".curdir.">")
8261 return b:netrw_curdir
8262endfun
8263
8264" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008265" s:NetrwOpenFile: query user for a filename and open it {{{2
8266fun! s:NetrwOpenFile(islocal)
8267" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008268 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008269 call inputsave()
8270 let fname= input("Enter filename: ")
8271 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008272" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8273
8274 " determine if Lexplore is in use
8275 if exists("t:netrw_lexbufnr")
8276 " check if t:netrw_lexbufnr refers to a netrw window
8277" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8278 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8279 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8280" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8281 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8282 exe "NetrwKeepj e ".fnameescape(fname)
8283 let @@= ykeep
8284" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8285 endif
8286 endif
8287
8288 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008289 if fname !~ '[/\\]'
8290 if exists("b:netrw_curdir")
8291 if exists("g:netrw_quiet")
8292 let netrw_quiet_keep = g:netrw_quiet
8293 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008294 let g:netrw_quiet = 1
8295 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008296 let s:rexposn_{bufnr("%")}= winsaveview()
8297" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008298 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008299 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008300 else
8301 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8302 endif
8303 if exists("netrw_quiet_keep")
8304 let g:netrw_quiet= netrw_quiet_keep
8305 else
8306 unlet g:netrw_quiet
8307 endif
8308 endif
8309 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008310 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008311 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008312 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008313" call Dret("s:NetrwOpenFile")
8314endfun
8315
8316" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008317" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8318" For the mapping to this function be made via
8319" netrwPlugin, you'll need to have had
8320" g:netrw_usetab set to non-zero.
8321fun! netrw#Shrink()
8322" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8323 let curwin = winnr()
8324 let wiwkeep = &wiw
8325 set wiw=1
8326
8327 if &ft == "netrw"
8328 if winwidth(0) > g:netrw_wiw
8329 let t:netrw_winwidth= winwidth(0)
8330 exe "vert resize ".g:netrw_wiw
8331 wincmd l
8332 if winnr() == curwin
8333 wincmd h
8334 endif
8335" call Decho("vert resize 0",'~'.expand("<slnum>"))
8336 else
8337 exe "vert resize ".t:netrw_winwidth
8338" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8339 endif
8340
8341 elseif exists("t:netrw_lexbufnr")
8342 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8343 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8344 let t:netrw_winwidth= winwidth(0)
8345 exe "vert resize ".g:netrw_wiw
8346 wincmd l
8347 if winnr() == curwin
8348 wincmd h
8349 endif
8350" call Decho("vert resize 0",'~'.expand("<slnum>"))
8351 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8352 exe "vert resize ".t:netrw_winwidth
8353" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8354 else
8355 call netrw#Lexplore(0,0)
8356 endif
8357
8358 else
8359 call netrw#Lexplore(0,0)
8360 endif
8361 let wiw= wiwkeep
8362
8363" call Dret("netrw#Shrink")
8364endfun
8365
8366" ---------------------------------------------------------------------
8367" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8368fun! s:NetSortSequence(islocal)
8369" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8370
8371 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008372 let svpos= winsaveview()
8373" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008374 call inputsave()
8375 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8376 call inputrestore()
8377
8378 " refresh the listing
8379 let g:netrw_sort_sequence= newsortseq
8380 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008381" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8382 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008383 let @@= ykeep
8384
8385" call Dret("NetSortSequence")
8386endfun
8387
8388" ---------------------------------------------------------------------
8389" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8390" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008391" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008392fun! s:NetrwUnmarkList(curbufnr,curdir)
8393" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8394
8395 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008396 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008397 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8398 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8399 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8400 call remove(s:netrwmarkfilelist,idx) " remove from global list
8401 endfor
8402 if s:netrwmarkfilelist == []
8403 unlet s:netrwmarkfilelist
8404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008405
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406 " getting rid of the local marked-file lists is easy
8407 unlet s:netrwmarkfilelist_{a:curbufnr}
8408 endif
8409 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8410 unlet s:netrwmarkfilemtch_{a:curbufnr}
8411 endif
8412 2match none
8413" call Dret("s:NetrwUnmarkList")
8414endfun
8415
8416" ---------------------------------------------------------------------
8417" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8418fun! s:NetrwUnmarkAll()
8419" call Dfunc("s:NetrwUnmarkAll()")
8420 if exists("s:netrwmarkfilelist")
8421 unlet s:netrwmarkfilelist
8422 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008423 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424 2match none
8425" call Dret("s:NetrwUnmarkAll")
8426endfun
8427
8428" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008429" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430fun! s:NetrwUnmarkAll2()
8431" call Dfunc("s:NetrwUnmarkAll2()")
8432 redir => netrwmarkfilelist_let
8433 let
8434 redir END
8435 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008436 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8438 for flist in netrwmarkfilelist_list
8439 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8440 unlet s:netrwmarkfilelist_{curbufnr}
8441 unlet s:netrwmarkfilemtch_{curbufnr}
8442 endfor
8443" call Dret("s:NetrwUnmarkAll2")
8444endfun
8445
8446" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008447" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8448"
8449" Marked files are in two types of lists:
8450" s:netrwmarkfilelist -- holds complete paths to all marked files
8451" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8452"
8453" Marked files suitable for use with 2match are in:
8454" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455fun! s:NetrwUnMarkFile(islocal)
8456" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008457 let svpos = winsaveview()
8458" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 let curbufnr = bufnr("%")
8460
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461 " unmark marked file list
8462 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8463 if exists("s:netrwmarkfilelist")
8464" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008466 endif
8467
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008468 let ibuf= 1
8469 while ibuf < bufnr("$")
8470 if exists("s:netrwmarkfilelist_".ibuf)
8471 unlet s:netrwmarkfilelist_{ibuf}
8472 unlet s:netrwmarkfilemtch_{ibuf}
8473 endif
8474 let ibuf = ibuf + 1
8475 endwhile
8476 2match none
8477
Bram Moolenaar446cb832008-06-24 21:56:24 +00008478" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008479"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8480call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481" call Dret("s:NetrwUnMarkFile")
8482endfun
8483
8484" ---------------------------------------------------------------------
8485" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8486fun! s:NetrwMenu(domenu)
8487
8488 if !exists("g:NetrwMenuPriority")
8489 let g:NetrwMenuPriority= 80
8490 endif
8491
Bram Moolenaaradc21822011-04-01 18:03:16 +02008492 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8494
8495 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008496" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008498 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8502 if g:netrw_dirhistmax > 0
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8507 else
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8509 endif
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8524 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 +01008525 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 +02008526 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8555 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>'
8556 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>'
8557 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>'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8559 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>'
8560 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>'
8561 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 +01008562 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 +02008563 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008566 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8567 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568
8569 elseif !a:domenu
8570 let s:netrwcnt = 0
8571 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008572 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 exe curwin."wincmd w"
8574
8575 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008576" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008577 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008578" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008579 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008580 endif
8581 endif
8582" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008583 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584 endif
8585
8586endfun
8587
8588" ---------------------------------------------------------------------
8589" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8590" Used by the O maps (as <SID>NetrwObtain())
8591fun! s:NetrwObtain(islocal)
8592" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8593
Bram Moolenaar97d62492012-11-15 21:28:22 +01008594 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008595 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008596 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008597 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8599 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008600 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008602 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603
8604" call Dret("NetrwObtain")
8605endfun
8606
8607" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008608" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8609" If there's only one window, then the window will first be split.
8610" Returns:
8611" choice = 0 : didn't have to choose
8612" choice = 1 : saved modified file in window first
8613" choice = 2 : didn't save modified file, opened window
8614" choice = 3 : cancel open
8615fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008616" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008617
Bram Moolenaar97d62492012-11-15 21:28:22 +01008618 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008619 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008620 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008621" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622
8623 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008624 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008626" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8627" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8628 let curword = s:NetrwGetWord()
8629 let choice = 0
8630 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8631" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008632 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008633" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008634 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008635" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008636" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008637" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638
Bram Moolenaar8d043172014-01-23 14:24:41 +01008639 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 if lastwinnr == 1
8641 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008642" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008643 " g:netrw_preview=0: preview window shown in a horizontally split window
8644 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008646 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008647 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008648" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008649 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008651 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008652 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008653" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008654 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008655 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008657" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658
8659 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008660" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008661 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008662" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008663 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008664" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008665 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008666" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008667 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008668" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008669" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008670" call Decho("COMBAK#12: mod=".&mod)
8671
8672 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8673 " whoops -- user trying to open file in the Lexplore window.
8674 " Use Lexplore's opening-file window instead.
8675" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8676" exe g:netrw_chgwin."wincmd w"
8677 wincmd p
8678 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8679 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008680
8681 " prevwinnr: the window number of the "prev" window
8682 " prevbufnr: the buffer number of the buffer in the "prev" window
8683 " bnrcnt : the qty of windows open on the "prev" buffer
8684 let prevwinnr = winnr()
8685 let prevbufnr = bufnr("%")
8686 let prevbufname = bufname("%")
8687 let prevmod = &mod
8688 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008689" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008690 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008693
8694 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008695 " and it doesn't appear in any other extant window, then ask the
8696 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008697 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008698" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008701 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008702" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008703
8704 if bnrcnt == 1 && &hidden == 0
8705 " only one copy of the modified buffer in a window, and
8706 " hidden not set, so overwriting will lose the modified file. Ask first...
8707 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008708" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008709 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008710" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008711
8712 if choice == 1
8713 " Yes -- write file & then browse
8714 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008715 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008716 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008717 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008718 exe origwin."wincmd w"
8719 let &ei = eikeep
8720 let @@ = ykeep
8721" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722 return choice
8723 endif
8724
8725 elseif choice == 2
8726 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008727" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008728 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008729
8730 else
8731 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008732" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008733 exe origwin."wincmd w"
8734 let &ei= eikeep
8735 let @@ = ykeep
8736" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737 return choice
8738 endif
8739 endif
8740 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008741 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008743" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744
8745 " restore b:netrw_curdir (window split/enew may have lost it)
8746 let b:netrw_curdir= curdir
8747 if a:islocal < 2
8748 if a:islocal
8749 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8750 else
8751 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8752 endif
8753 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008754 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008755" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008756 return choice
8757endfun
8758
8759" ---------------------------------------------------------------------
8760" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8761" Always assumed to be local -> remote
8762" call s:NetrwUpload(filename, target)
8763" call s:NetrwUpload(filename, target, fromdirectory)
8764fun! s:NetrwUpload(fname,tgt,...)
8765" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8766
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008767 if a:tgt =~ '^\a\{3,}://'
8768 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008769 else
8770 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773
8774 if a:0 > 0
8775 let fromdir= a:1
8776 else
8777 let fromdir= getcwd()
8778 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008779" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780
8781 if type(a:fname) == 1
8782 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008784 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8786 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8787" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008788 if a:tgt =~ '/$'
8789 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008790" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008791 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008794 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008795" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796 endif
8797 q!
8798
8799 elseif type(a:fname) == 3
8800 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008801" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 let curdir= getcwd()
8803 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008804 if s:NetrwLcd(fromdir)
8805" call Dret("s:NetrwUpload : lcd failure")
8806 return
8807 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008808 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 if exists("g:netrw_port") && g:netrw_port != ""
8811 let useport= " ".g:netrw_scpport." ".g:netrw_port
8812 else
8813 let useport= ""
8814 endif
8815 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8816 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008817 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 +02008818 if s:NetrwLcd(curdir)
8819" call Dret("s:NetrwUpload : lcd failure")
8820 return
8821 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822
8823 elseif a:tgt =~ '^ftp:'
8824 call s:NetrwMethod(a:tgt)
8825
8826 if b:netrw_method == 2
8827 " handle uploading a list of files via ftp+.netrc
8828 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008832 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008833" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008834
8835 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838 endif
8839
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008840 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842
Bram Moolenaaradc21822011-04-01 18:03:16 +02008843 if tgtdir == ""
8844 let tgtdir= '/'
8845 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008846 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008848
8849 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8851" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 endfor
8853
8854 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008855 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 +00008856 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008857" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8858 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008859 endif
8860 " 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 +01008861 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008862 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8864 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8865 else
8866 bw!|q
8867 endif
8868
8869 elseif b:netrw_method == 3
8870 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8871 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008872 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008873 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008874 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875
8876 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008877 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008878" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008880 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008882 endif
8883
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008884 if exists("g:netrw_uid") && g:netrw_uid != ""
8885 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008889 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008890 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008891" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008892 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008893 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008894" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008895 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 endif
8897
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008898 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008899" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008900
8901 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 endif
8905
8906 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008907 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008908" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008909 endif
8910
8911 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008912 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008913" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008914 endfor
8915
8916 " perform ftp:
8917 " -i : turns off interactive prompting from ftp
8918 " -n unix : DON'T use <.netrc>, even though it exists
8919 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008920 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008921 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 " 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 +01008923 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008924 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008925 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8926 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008927 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8929 let &debug = debugkeep
8930 let mod = 1
8931 else
8932 bw!|q
8933 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008934 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008935" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008936 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008937 endif
8938 else
8939 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8940 endif
8941 endif
8942
8943" call Dret("s:NetrwUpload")
8944endfun
8945
8946" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008947" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008948fun! s:NetrwPreview(path) range
8949" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8951" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008952 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953 NetrwKeepj call s:NetrwOptionsSave("s:")
8954 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8955 NetrwKeepj call s:NetrwOptionsSafe(1)
8956 else
8957 NetrwKeepj call s:NetrwOptionsSafe(0)
8958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008959 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008960" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008961 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008962" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8963 if g:netrw_preview
8964 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008965 let pvhkeep = &pvh
8966 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8967 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008968" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8969 else
8970 " horizontal split
8971 let pvhkeep = &pvh
8972 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8973 let &pvh = winheight(0) - winsz
8974" 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 +02008975 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008976 " g:netrw_preview g:netrw_alto
8977 " 1 : vert 1: top -- preview window is vertically split off and on the left
8978 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8979 " 0 : 1: top -- preview window is horizontally split off and on the top
8980 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8981 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008982 " 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 +02008983 " the BufEnter event set up in netrwPlugin.vim
8984" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8985 let eikeep = &ei
8986 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008987 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008988 let &ei= eikeep
8989" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008990 if exists("pvhkeep")
8991 let &pvh= pvhkeep
8992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008993 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008994 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008995 endif
8996 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008997 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 +00008998 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008999 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009000 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001" call Dret("NetrwPreview")
9002endfun
9003
9004" ---------------------------------------------------------------------
9005" s:NetrwRefresh: {{{2
9006fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009007" 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 +00009008 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009009 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009010" call Decho("setl ma noro",'~'.expand("<slnum>"))
9011" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009012 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009013 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9014 if !exists("w:netrw_treetop")
9015 if exists("b:netrw_curdir")
9016 let w:netrw_treetop= b:netrw_curdir
9017 else
9018 let w:netrw_treetop= getcwd()
9019 endif
9020 endif
9021 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9022 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009023
9024 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009025 let screenposn = winsaveview()
9026" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009027
9028" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9029" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9030 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009031 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009032 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009034 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009035 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009036
9037 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009038" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9039 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009040
9041 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009042 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9043 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9044" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9045 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9046 else
9047" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9048 2match none
9049 endif
9050 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051
Bram Moolenaar97d62492012-11-15 21:28:22 +01009052" restore
9053 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009054" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055endfun
9056
9057" ---------------------------------------------------------------------
9058" s:NetrwRefreshDir: refreshes a directory by name {{{2
9059" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009060" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009062" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 if g:netrw_fastbrowse == 0
9064 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009067" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009068
9069 if tgtwin > 0
9070 " tgtwin is being displayed, so refresh it
9071 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009074 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 exe curwin."wincmd w"
9076
9077 elseif bufnr(a:dirname) > 0
9078 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009079" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9080 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 endif
9082
9083 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009084" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086 endif
9087" call Dret("s:NetrwRefreshDir")
9088endfun
9089
9090" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009091" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9092" window number to do its editing in.
9093" Supports [count]C where the count, if present, is used to specify
9094" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009095fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009096" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009097 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009098" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 if a:1 == "" " :NetrwC win#
9100 let g:netrw_chgwin= winnr()
9101 else " :NetrwC
9102 let g:netrw_chgwin= a:1
9103 endif
9104 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009105 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009106 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009107 let g:netrw_chgwin= winnr()
9108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009109 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009110" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009111endfun
9112
9113" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009114" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9115" What this function does is to compute a priority for the patterns
9116" in the g:netrw_sort_sequence. It applies a substitute to any
9117" "files" that satisfy each pattern, putting the priority / in
9118" front. An "*" pattern handles the default priority.
9119fun! s:NetrwSetSort()
9120" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009121 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009122 if w:netrw_liststyle == s:LONGLIST
9123 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9124 else
9125 let seqlist = g:netrw_sort_sequence
9126 endif
9127 " sanity check -- insure that * appears somewhere
9128 if seqlist == ""
9129 let seqlist= '*'
9130 elseif seqlist !~ '\*'
9131 let seqlist= seqlist.',*'
9132 endif
9133 let priority = 1
9134 while seqlist != ""
9135 if seqlist =~ ','
9136 let seq = substitute(seqlist,',.*$','','e')
9137 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9138 else
9139 let seq = seqlist
9140 let seqlist = ""
9141 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009143 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009145 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009147 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009149" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150
9151 " sanity check
9152 if w:netrw_bannercnt > line("$")
9153 " apparently no files were left after a Hiding pattern was used
9154" call Dret("SetSort : no files left after hiding")
9155 return
9156 endif
9157 if seq == '*'
9158 let starpriority= spriority
9159 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009160 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009161 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 " sometimes multiple sorting patterns will match the same file or directory.
9163 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009164 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9165 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166 endif
9167 let priority = priority + 1
9168 endwhile
9169 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009170 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9171 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172 endif
9173
9174 " Following line associated with priority -- items that satisfy a priority
9175 " pattern get prefixed by ###/ which permits easy sorting by priority.
9176 " Sometimes files can satisfy multiple priority patterns -- only the latest
9177 " priority pattern needs to be retained. So, at this point, these excess
9178 " priority prefixes need to be removed, but not directories that happen to
9179 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009180 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9181 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009182 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009183
9184" call Dret("SetSort")
9185endfun
9186
Bram Moolenaarff034192013-04-24 18:51:19 +02009187" ---------------------------------------------------------------------
9188" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9189" Implements [count]Tb (bookhist<b>)
9190" [count]Th (bookhist<h>)
9191" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009192fun! s:NetrwSetTgt(islocal,bookhist,choice)
9193" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009194
9195 if a:bookhist == 'b'
9196 " supports choosing a bookmark as a target using a qb-generated list
9197 let choice= a:choice - 1
9198 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009199 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009200 else
9201 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9202 endif
9203
9204 elseif a:bookhist == 'h'
9205 " supports choosing a history stack entry as a target using a qb-generated list
9206 let choice= (a:choice % g:netrw_dirhistmax) + 1
9207 if exists("g:netrw_dirhist_".choice)
9208 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009209 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009210 else
9211 echomsg "Sorry, history#".a:choice." not available!"
9212 endif
9213 endif
9214
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009215 " refresh the display
9216 if !exists("b:netrw_curdir")
9217 let b:netrw_curdir= getcwd()
9218 endif
9219 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9220
Bram Moolenaarff034192013-04-24 18:51:19 +02009221" call Dret("s:NetrwSetTgt")
9222endfun
9223
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009225" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009226fun! s:NetrwSortStyle(islocal)
9227" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009228 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009229 let svpos= winsaveview()
9230" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009231
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009232 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 +01009233 NetrwKeepj norm! 0
9234 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009235" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9236 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009237
9238" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9239endfun
9240
9241" ---------------------------------------------------------------------
9242" s:NetrwSplit: mode {{{2
9243" =0 : net and o
9244" =1 : net and t
9245" =2 : net and v
9246" =3 : local and o
9247" =4 : local and t
9248" =5 : local and v
9249fun! s:NetrwSplit(mode)
9250" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9251
Bram Moolenaar97d62492012-11-15 21:28:22 +01009252 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 call s:SaveWinVars()
9254
9255 if a:mode == 0
9256 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009257 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009258 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009260 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj call s:RestoreWinVars()
9263 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 unlet s:didsplit
9265
9266 elseif a:mode == 1
9267 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009268 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009269" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270 tabnew
9271 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009272 NetrwKeepj call s:RestoreWinVars()
9273 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009274 unlet s:didsplit
9275
9276 elseif a:mode == 2
9277 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009278 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009279 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009280" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009281 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009282 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009283 NetrwKeepj call s:RestoreWinVars()
9284 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009285 unlet s:didsplit
9286
9287 elseif a:mode == 3
9288 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009289 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009290 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009292 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009294 NetrwKeepj call s:RestoreWinVars()
9295 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296 unlet s:didsplit
9297
9298 elseif a:mode == 4
9299 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009300 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009301 let eikeep = &ei
9302 let netrw_winnr = winnr()
9303 let netrw_line = line(".")
9304 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009305 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009306 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009307 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009308 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9309 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009310 let &ei = eikeep
9311 let netrw_curdir = s:NetrwTreeDir(0)
9312" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009314 let b:netrw_curdir = netrw_curdir
9315 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009316 NetrwKeepj call s:RestoreWinVars()
9317 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009318 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009319 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009320 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9321 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009322 let &ei= eikeep
9323 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009324 unlet s:didsplit
9325
9326 elseif a:mode == 5
9327 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009328 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009329 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009330" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009331 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009333 NetrwKeepj call s:RestoreWinVars()
9334 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335 unlet s:didsplit
9336
9337 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009338 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009339 endif
9340
Bram Moolenaar97d62492012-11-15 21:28:22 +01009341 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009342" call Dret("s:NetrwSplit")
9343endfun
9344
9345" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009346" s:NetrwTgtMenu: {{{2
9347fun! s:NetrwTgtMenu()
9348 if !exists("s:netrw_menucnt")
9349 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009350 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009351" call Dfunc("s:NetrwTgtMenu()")
9352
9353 " the following test assures that gvim is running, has menus available, and has menus enabled.
9354 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9355 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009357 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9358 endif
9359 if !exists("s:netrw_initbookhist")
9360 call s:NetrwBookHistRead()
9361 endif
9362
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009363 " try to cull duplicate entries
9364 let tgtdict={}
9365
Bram Moolenaarff034192013-04-24 18:51:19 +02009366 " target bookmarked places
9367 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 let cnt= 1
9370 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371 if has_key(tgtdict,bmd)
9372 let cnt= cnt + 1
9373 continue
9374 endif
9375 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009376 let ebmd= escape(bmd,g:netrw_menu_escape)
9377 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009378" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009379 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 +02009380 let cnt= cnt + 1
9381 endfor
9382 endif
9383
9384 " target directory browsing history
9385 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009386" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009387 let histcnt = 1
9388 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009389 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009390 if exists("g:netrw_dirhist_{histcnt}")
9391 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392 if has_key(tgtdict,histentry)
9393 let histcnt = histcnt + 1
9394 continue
9395 endif
9396 let tgtdict[histentry] = histcnt
9397 let ehistentry = escape(histentry,g:netrw_menu_escape)
9398" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009399 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 +02009400 endif
9401 let histcnt = histcnt + 1
9402 endwhile
9403 endif
9404 endif
9405" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406endfun
9407
9408" ---------------------------------------------------------------------
9409" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9410" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009411fun! s:NetrwTreeDir(islocal)
9412" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009413" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009414" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9415" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9416" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009417" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009418
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009419 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009420 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009422 let treedir= s:treedir
9423 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009424 unlet s:prevwinopen
9425" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009426 return treedir
9427 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009428 if exists("s:prevwinopen")
9429 unlet s:prevwinopen
9430 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009432
Bram Moolenaar8d043172014-01-23 14:24:41 +01009433 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9434 let b:netrw_curdir= getcwd()
9435 endif
9436 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009437" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009438" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009439
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009440 let s:treecurpos= winsaveview()
9441" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009442" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009443
9444 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9446" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009447" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009448
9449 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009450 let curline= substitute(getline('.'),"\t -->.*$",'','')
9451 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009453 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9455 elseif curline =~ '@$'
9456" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009457 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461 let treedir= ""
9462 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009463" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464
9465 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009466" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9467" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009468" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009469 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009470" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009471 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9473 sil! NetrwKeepj %d _
9474" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009476" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009477" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009478 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009479" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009480
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009481" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009482" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009483" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009484
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009485 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9486" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9487" let newdir = w:netrw_treetop.'/'.potentialdir
9488" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9489" let treedir = s:NetrwTreePath(newdir)
9490" let w:netrw_treetop = newdir
9491" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9492" else
9493" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009494 if a:islocal && curline =~ '@$'
9495 if isdirectory(s:NetrwFile(potentialdir))
9496 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9497 let w:netrw_treetop = treedir
9498 endif
9499 else
9500 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9501 let treedir = s:NetrwTreePath(w:netrw_treetop)
9502 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009504" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009505
9506 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009507 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009509" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009510
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009511" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009512 return treedir
9513endfun
9514
9515" ---------------------------------------------------------------------
9516" s:NetrwTreeDisplay: recursive tree display {{{2
9517fun! s:NetrwTreeDisplay(dir,depth)
9518" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9519
9520 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009521 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522
9523 " install ../ and shortdir
9524 if a:depth == ""
9525 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009526" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009527 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009528 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009529 if a:dir == w:netrw_treetop
9530 let shortdir= a:dir
9531 else
9532 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9533 endif
9534 call setline(line("$")+1,a:depth.shortdir)
9535 else
9536 let shortdir= substitute(a:dir,'^.*/','','e')
9537 call setline(line("$")+1,a:depth.shortdir.'/')
9538 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009539" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009540 " append a / to dir if its missing one
9541 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009542
9543 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009544 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009545" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009546
Bram Moolenaar85850f32019-07-19 22:05:51 +02009547 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9548 if g:netrw_hide == 1
9549 " hide given patterns
9550 let listhide= split(g:netrw_list_hide,',')
9551" call Decho("listhide=".string(listhide))
9552 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009553 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009554 endfor
9555
9556 elseif g:netrw_hide == 2
9557 " show given patterns (only)
9558 let listhide= split(g:netrw_list_hide,',')
9559" call Decho("listhide=".string(listhide))
9560 let entries=[]
9561 for entry in w:netrw_treedict[dir]
9562 for pat in listhide
9563 if entry =~ pat
9564 call add(entries,entry)
9565 break
9566 endif
9567 endfor
9568 endfor
9569 let w:netrw_treedict[dir]= entries
9570 endif
9571 if depth != ""
9572 " always remove "." and ".." entries when there's depth
9573 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9574 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9575 endif
9576
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009577" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009578 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009579 if dir =~ '/$'
9580 let direntry= substitute(dir.entry,'[@/]$','','e')
9581 else
9582 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009584" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009586" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009587 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009589" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9590 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9591 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9592" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009593 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009595" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009596 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009597 endif
9598 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009599" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009600
Bram Moolenaar446cb832008-06-24 21:56:24 +00009601" call Dret("NetrwTreeDisplay")
9602endfun
9603
9604" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009605" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9606fun! s:NetrwRefreshTreeDict(dir)
9607" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009608 if !exists("w:netrw_treedict")
9609" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9610 return
9611 endif
9612
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009613 for entry in w:netrw_treedict[a:dir]
9614 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9615" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9616
9617 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9618" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9619 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009620 let liststar = s:NetrwGlob(direntry,'*',1)
9621 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009622 let w:netrw_treedict[direntry] = liststar + listdotstar
9623" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9624
9625 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9626" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9627 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009628 let liststar = s:NetrwGlob(direntry.'/','*',1)
9629 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009630 let w:netrw_treedict[direntry]= liststar + listdotstar
9631" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9632
9633 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9634" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9635 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009636 let liststar = s:NetrwGlob(direntry.'/','*',1)
9637 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009638" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9639
9640 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009641" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009642 endif
9643 endfor
9644" call Dret("s:NetrwRefreshTreeDict")
9645endfun
9646
9647" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009649" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009651 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009652" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009653" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9654" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
9655" 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 +00009656
9657 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009661 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009662" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009664" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009666 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009669 if exists("w:netrw_treetop")
9670 let s:netrw_treetop= w:netrw_treetop
9671 else
9672 let w:netrw_treetop= getcwd()
9673 let s:netrw_treetop= w:netrw_treetop
9674 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009675
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677 " insure that we have a treedict, albeit empty
9678" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treedict= {}
9680 endif
9681
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009682 " update the dictionary for the current directory
9683" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009685 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009688 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689
9690 " if past banner, record word
9691 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9692 let fname= expand("<cword>")
9693 else
9694 let fname= ""
9695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009696" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9697" 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 +00009698
9699 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009700" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009701 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009702" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009703
9704 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9705 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009706" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009707 1d
9708 endwhile
9709
Bram Moolenaar13600302014-05-22 18:26:40 +02009710 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009711
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009712" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009713 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009714 endif
9715endfun
9716
9717" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009718" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009719" Normally, treetop is w:netrw_treetop, but a
9720" user of the function ( netrw#SetTreetop() )
9721" wipes that out prior to calling this function
9722fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009723" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9724 if line(".") < w:netrw_bannercnt + 2
9725 let treedir= a:treetop
9726 if treedir !~ '/$'
9727 let treedir= treedir.'/'
9728 endif
9729" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9730 return treedir
9731 endif
9732
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009733 let svpos = winsaveview()
9734" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009735 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009736" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009737 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009738" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9739 let curline= getline('.')
9740" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9741 if curline =~ '/$'
9742" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9743 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9744" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9745 elseif curline =~ '@\s\+-->'
9746" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9747 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9748 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9749" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009751" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 let treedir= ""
9753 endif
9754 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009755" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9756" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9758 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9759 let treedir= dirname.treedir
9760 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009762 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009763" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009764 if a:treetop =~ '/$'
9765 let treedir= a:treetop.treedir
9766 else
9767 let treedir= a:treetop.'/'.treedir
9768 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009769" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009770 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009771" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009772" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9773 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009774" call Dret("s:NetrwTreePath <".treedir.">")
9775 return treedir
9776endfun
9777
9778" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779" s:NetrwWideListing: {{{2
9780fun! s:NetrwWideListing()
9781
9782 if w:netrw_liststyle == s:WIDELIST
9783" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9784 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009785 " cpf: characters per filename
9786 " fpl: filenames per line
9787 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009788 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009789 let dict={}
9790 " save the unnamed register and register 0-9 and a
9791 let dict.a=[getreg('a'), getregtype('a')]
9792 for i in range(0, 9)
9793 let dict[i] = [getreg(i), getregtype(i)]
9794 endfor
9795 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009796" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009797 let b:netrw_cpf= 0
9798 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009799 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009800 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9801 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009803 " restore stored registers
9804 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805" call Dret("NetrwWideListing")
9806 return
9807 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009808 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009809 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811
9812 " determine qty files per line (fpl)
9813 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9814 if w:netrw_fpl <= 0
9815 let w:netrw_fpl= 1
9816 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818
9819 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009820 " fpc: files per column of wide listing
9821 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009822 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009823 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9824 let newcolstart = w:netrw_bannercnt + fpc
9825 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009826" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009827 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009828" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009829 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009830 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009831 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 while line("$") >= newcolstart
9833 if newcolend > line("$") | let newcolend= line("$") | endif
9834 let newcolqty= newcolend - newcolstart
9835 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009836 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009838 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009840 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009842 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009843 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009845 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009846" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009847 if @* != keepregstar | sil! let @* = keepregstar | endif
9848 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009849 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009850 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9851 NetrwKeepj call histdel("/",-1)
9852 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9853 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009855 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009856 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009857" 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 +00009858" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009859 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009860 else
9861 if hasmapto("w","n")
9862 sil! nunmap <buffer> w
9863 endif
9864 if hasmapto("b","n")
9865 sil! nunmap <buffer> b
9866 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009867 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868endfun
9869
9870" ---------------------------------------------------------------------
9871" s:PerformListing: {{{2
9872fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9874" 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 +02009875" 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>"))
9876 sil! NetrwKeepj %d _
9877" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878
Bram Moolenaar15146672011-10-20 22:22:38 +02009879 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009880" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009881 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009882
Bram Moolenaar85850f32019-07-19 22:05:51 +02009883 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009884 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009885" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886
9887" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009888" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889" endif " Decho
9890
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009891" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009892 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9893 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009894" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9895 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009896 endif
9897
9898 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009899 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900
9901 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009902 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009904 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905 if exists("g:netrw_pchk")
9906 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9907 " failure detections.
9908 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009909 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009910 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9911 endif
9912 if exists("g:netrw_pchk")
9913 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9914 else
9915 let curdir= b:netrw_curdir
9916 endif
9917 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9918 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9919 else
9920 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009921 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009922 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009923 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009924 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009925" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009926 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009927 let w:netrw_bannercnt= 1
9928 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009929" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9930" 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 +00009931
Bram Moolenaar85850f32019-07-19 22:05:51 +02009932 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009934 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935 let sortby= sortby." reversed"
9936 endif
9937
9938 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009939 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009941 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009943 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009944 NetrwKeepj put ='\" Sorted by '.sortby
9945 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009946 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9947 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009949 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009950 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009951 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9952 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009953 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009954" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009955" 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 +00009956 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009957
Bram Moolenaar85850f32019-07-19 22:05:51 +02009958 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009959 if g:netrw_banner
9960 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009961" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009965 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009966 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 endif
9968 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009969 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009970" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009971 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974
9975 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009977" 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 +01009978 if g:netrw_list_hide != "" && g:netrw_hide
9979 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009981 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009982 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009983 endif
9984 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009987
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" 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 +01009989 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009991 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" 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 +01009993 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009994 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009995" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" 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 +00009997 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998
9999 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010000 if g:netrw_banner
10001 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010002 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010003" 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 +010010004" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010005" 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 +010010006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010007
Bram Moolenaar446cb832008-06-24 21:56:24 +000010008 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010011 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010013 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010014 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" 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 +010010016" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10017 return
10018 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010019 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020
10021 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010022 if !exists("w:netrw_bannercnt")
10023 let w:netrw_bannercnt= 0
10024 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010025" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10026" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10027" 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 +010010028
Bram Moolenaar5c736222010-01-06 20:54:52 +010010029 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010030" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" 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 +000010032 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010033 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010034 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010035 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010036" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010038 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010039 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010040" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010041 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042
Bram Moolenaar5c736222010-01-06 20:54:52 +010010043 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010044" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010045 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010046 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010047 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048 else
10049 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010050 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051 endif
10052 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010053
Bram Moolenaar446cb832008-06-24 21:56:24 +000010054 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010055" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010056 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10057 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010059 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010060 " exten: sort by extension
10061 " The histdel(...,-1) calls remove the last search from the search history
10062" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10064 NetrwKeepj call histdel("/",-1)
10065 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10066 NetrwKeepj call histdel("/",-1)
10067 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10068 NetrwKeepj call histdel("/",-1)
10069 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10070" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010071 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010072 " normal direction sorting
10073 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10074 else
10075 " reverse direction sorting
10076 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10077 endif
10078 endif
10079 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10080 NetrwKeepj call histdel("/",-1)
10081
Bram Moolenaar446cb832008-06-24 21:56:24 +000010082 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010083 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010084" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010085 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010086" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010087 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010088 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010089" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010090 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010091 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010092" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010093 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10094 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010096 endif
10097
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010098 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010100 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010102 call histdel("/",-1)
10103 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 endif
10105 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106" 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 +000010107
10108 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10110" 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 +010010111 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" 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 +000010115
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010116 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010117 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010119 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010120 endif
10121
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010123 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10125 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010126 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10128 else
10129" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10130" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10131" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10132" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010133 endif
10134
10135 " record previous current directory
10136 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010138
10139 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10141" 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 +010010142 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010144 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" 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 +000010146
10147 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010149 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" 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 +010010151 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010153 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10154 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010155" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010156" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010157
Bram Moolenaar8d043172014-01-23 14:24:41 +010010158 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10160" 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 +010010161" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10162 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010163 unlet s:treecurpos
10164 endif
10165
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010166" 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>"))
10167" 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 +000010168" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10169endfun
10170
10171" ---------------------------------------------------------------------
10172" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010173fun! s:SetupNetrwStatusLine(statline)
10174" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10175
10176 if !exists("s:netrw_setup_statline")
10177 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010178" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010179
10180 if !exists("s:netrw_users_stl")
10181 let s:netrw_users_stl= &stl
10182 endif
10183 if !exists("s:netrw_users_ls")
10184 let s:netrw_users_ls= &laststatus
10185 endif
10186
10187 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010188 let dict={}
10189 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010190 redir @a
10191 try
10192 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010193 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010194 if &bg == "dark"
10195 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10196 else
10197 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10198 endif
10199 endtry
10200 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010201 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010202 endif
10203
10204 " set up status line (may use User9 highlighting)
10205 " insure that windows have a statusline
10206 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010207 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010208 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010209" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010210 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010211
10212" call Dret("SetupNetrwStatusLine : stl=".&stl)
10213endfun
10214
Bram Moolenaar85850f32019-07-19 22:05:51 +020010215" =========================================
10216" Remote Directory Browsing Support: {{{1
10217" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010218
10219" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010220" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10221" This function assumes that a long listing will be received. Size, time,
10222" and reverse sorts will be requested of the server but not otherwise
10223" enforced here.
10224fun! s:NetrwRemoteFtpCmd(path,listcmd)
10225" 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 +010010226" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010227 " sanity check: {{{3
10228 if !exists("w:netrw_method")
10229 if exists("b:netrw_method")
10230 let w:netrw_method= b:netrw_method
10231 else
10232 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10233" call Dret("NetrwRemoteFtpCmd")
10234 return
10235 endif
10236 endif
10237
10238 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10239 let ffkeep= &ff
10240 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010241" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010242
10243 " clear off any older non-banner lines " {{{3
10244 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010245" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10246 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010247
10248 ".........................................
10249 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10250 " ftp + <.netrc>: Method #2
10251 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010252 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 endif
10254 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010255 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010256" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010259" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010260 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010261" 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>"))
10262 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 +010010263 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010264" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10265 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 +010010266 endif
10267
10268 ".........................................
10269 elseif w:netrw_method == 3 " {{{3
10270 " ftp + machine,id,passwd,filename: Method #3
10271 setl ff=unix
10272 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010273 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010275 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010276 endif
10277
10278 " handle userid and password
10279 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010280" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010281 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10282 call NetUserPass("ftp:".host)
10283 endif
10284 if exists("g:netrw_uid") && g:netrw_uid != ""
10285 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010286 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010288 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010289 endif
10290 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010291 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010292 endif
10293 endif
10294
10295 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010296 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 endif
10298 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010299 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010300" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010301 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010302 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010303
10304 " perform ftp:
10305 " -i : turns off interactive prompting from ftp
10306 " -n unix : DON'T use <.netrc>, even though it exists
10307 " -n win32: quit being obnoxious about password
10308 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010309" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010310 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010311" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010312" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10313" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010314 endif
10315
10316 ".........................................
10317 elseif w:netrw_method == 9 " {{{3
10318 " sftp username@machine: Method #9
10319 " s:netrw_sftp_cmd
10320 setl ff=unix
10321
10322 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010323 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010324" call Dret("NetrwRemoteFtpCmd")
10325 return
10326
10327 ".........................................
10328 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010330 endif
10331
10332 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010333 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010334 sil! NetrwKeepj %s/\r$//e
10335 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 endif
10337 if a:listcmd == "dir"
10338 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010339 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10340 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10341 NetrwKeepj call histdel("/",-1)
10342 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010343 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 +010010344 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10345 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 endif
10347 endif
10348
10349 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10350 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010351 exe 'NetrwKeepj '.w:netrw_bannercnt
10352 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010353 endif
10354 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010355 exe 'NetrwKeepj '.w:netrw_bannercnt
10356 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010357 endif
10358
10359 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010360 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010361" call Dret("NetrwRemoteFtpCmd")
10362endfun
10363
10364" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365" s:NetrwRemoteListing: {{{2
10366fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010367" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010368
Bram Moolenaara6878372014-03-22 21:02:50 +010010369 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10370 let w:netrw_bannercnt= s:bannercnt
10371 endif
10372 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010373 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010374 endif
10375
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010377
Bram Moolenaar446cb832008-06-24 21:56:24 +000010378 " sanity check:
10379 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010380" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 if !exists("g:netrw_quiet")
10384 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10385 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010386 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010387" call Dret("s:NetrwRemoteListing -1")
10388 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010389 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390
Bram Moolenaar8d043172014-01-23 14:24:41 +010010391 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010392" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010394 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010395 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 +000010396 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010397 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 +000010398 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010400
Bram Moolenaar85850f32019-07-19 22:05:51 +020010401 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010402" call Dret("s:NetrwRemoteListing -1")
10403 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010404 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010405" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010406
Bram Moolenaar446cb832008-06-24 21:56:24 +000010407 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 let w:netrw_method= b:netrw_method
10410 endif
10411
Bram Moolenaar13600302014-05-22 18:26:40 +020010412 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010413 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010415 let s:method = "ftp"
10416 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010417 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010419 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420 let listcmd= g:netrw_ftp_sizelist_cmd
10421 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010422" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010424" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010425
Bram Moolenaara6878372014-03-22 21:02:50 +010010426 " report on missing file or directory messages
10427 if search('[Nn]o such file or directory\|Failed to change directory')
10428 let mesg= getline(".")
10429 if exists("w:netrw_bannercnt")
10430 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010431 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010432 setl noma
10433 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010434 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010435 call netrw#ErrorMsg(s:WARNING,mesg,96)
10436" call Dret("s:NetrwRemoteListing : -1")
10437 return -1
10438 endif
10439
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010440 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 +000010441 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010442" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444
10445 " cleanup
10446 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010447 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10448 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010449 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 sil! NetrwKeepj %s/\r$//e
10451 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010453 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010456 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010459" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010460 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe "sil! NetrwKeepj ".line1
10463 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010465" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010466 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010467" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010468 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10469 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010472 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10473 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10474 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10475 NetrwKeepj call histdel("/",-1)
10476 NetrwKeepj call histdel("/",-1)
10477 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010478 endif
10479 endif
10480
Bram Moolenaar13600302014-05-22 18:26:40 +020010481 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010483" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010484 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010487" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10488 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010490 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10491 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10492 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10493 NetrwKeepj call histdel("/",-1)
10494 NetrwKeepj call histdel("/",-1)
10495 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010496 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010497 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10498 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499 endif
10500 else
10501 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010503 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010504 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010505" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10506 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10507" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 endif
10509 endif
10510
10511 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010512 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010513" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010514 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10515 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 endif
10517 endif
10518
10519 if w:netrw_liststyle == s:LONGLIST
10520 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010521" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010522
10523 if s:method == "ftp"
10524 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010526 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010527 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010529 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010531 sil! NetrwKeepj 1
10532 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010533 let line2= line(".")
10534 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010536 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 endif
10538 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010539 exe "sil! NetrwKeepj ".line1
10540 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 endif
10542
10543 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010545 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 +000010546 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010547" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010548 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010549 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010550 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10551 NetrwKeepj call histdel("/",-1)
10552 NetrwKeepj call histdel("/",-1)
10553 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 endif
10555 endif
10556
10557" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010558" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010560
10561" call Dret("s:NetrwRemoteListing 0")
10562 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010563endfun
10564
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565" ---------------------------------------------------------------------
10566" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10567fun! s:NetrwRemoteRm(usrhost,path) range
10568" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010569" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010570 let svpos= winsaveview()
10571" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572
10573 let all= 0
10574 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10575 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577 for fname in s:netrwmarkfilelist_{bufnr("%")}
10578 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010579 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010581 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 let all= 1
10583 endif
10584 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010585 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586
10587 else
10588 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010589" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590
10591 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592 let keepsol = &l:sol
10593 setl nosol
10594 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595
10596 " remove multiple files and directories
10597 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010598 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010600 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010602 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010603 let all= 1
10604 endif
10605 let ctr= ctr + 1
10606 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010607 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 endif
10609
10610 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010611" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010612 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010613" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10614 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615
10616" call Dret("s:NetrwRemoteRm")
10617endfun
10618
10619" ---------------------------------------------------------------------
10620" s:NetrwRemoteRmFile: {{{2
10621fun! s:NetrwRemoteRmFile(path,rmfile,all)
10622" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10623
10624 let all= a:all
10625 let ok = ""
10626
10627 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10628 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 if !all
10631 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010633 call inputsave()
10634 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10635 call inputrestore()
10636 echohl NONE
10637 if ok == ""
10638 let ok="no"
10639 endif
10640 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010641 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010642 let all= 1
10643 endif
10644 endif
10645
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010646 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010647" 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 +000010648 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010651 if path =~ '^\a\{3,}://'
10652 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010654 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10656 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010657" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010661 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 let ok="q"
10663 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010664 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10666" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10667" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010669 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010670 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010673" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010674 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675 if v:shell_error != 0
10676 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010677 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 +010010678 else
10679 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10680 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010681 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010682 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010684" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010685 endif
10686 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010687 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010688" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 endif
10690
10691 else
10692 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010694 if !all
10695 call inputsave()
10696 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10697 call inputrestore()
10698 if ok == ""
10699 let ok="no"
10700 endif
10701 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010702 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 let all= 1
10704 endif
10705 endif
10706
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010707 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010708 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010709 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010710 else
10711 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10713" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010714 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010715" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716
10717 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010718" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10719 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10720" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010721 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010722" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010723
10724 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010725 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010726 endif
10727 endif
10728 endif
10729
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010730 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010731" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732 endif
10733 endif
10734
10735" call Dret("s:NetrwRemoteRmFile ".ok)
10736 return ok
10737endfun
10738
10739" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740" s:NetrwRemoteRename: rename a remote file or directory {{{2
10741fun! s:NetrwRemoteRename(usrhost,path) range
10742" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10743
10744 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010745 let svpos = winsaveview()
10746" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 let ctr = a:firstline
10748 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10749
10750 " rename files given by the markfilelist
10751 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10752 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010753" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 if exists("subfrom")
10755 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010756" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010757 else
10758 call inputsave()
10759 let newname= input("Moving ".oldname." to : ",oldname)
10760 call inputrestore()
10761 if newname =~ '^s/'
10762 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10763 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10764 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766 endif
10767 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010768
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010770 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010771 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772 let oldname= s:ShellEscape(a:path.oldname)
10773 let newname= s:ShellEscape(a:path.newname)
10774" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010775 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 endif
10777
10778 endfor
10779 call s:NetrwUnMarkFile(1)
10780
10781 else
10782
10783 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010784 let keepsol= &l:sol
10785 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010786 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010787 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010788
10789 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010790" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010791
10792 call inputsave()
10793 let newname= input("Moving ".oldname." to : ",oldname)
10794 call inputrestore()
10795
10796 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10797 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10798 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799 let oldname= s:ShellEscape(a:path.oldname)
10800 let newname= s:ShellEscape(a:path.newname)
10801" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010802 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010803 endif
10804
10805 let ctr= ctr + 1
10806 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010807 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010808 endif
10809
10810 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010811 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010812" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10813 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010814
10815" call Dret("NetrwRemoteRename")
10816endfun
10817
Bram Moolenaar85850f32019-07-19 22:05:51 +020010818" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010819" Local Directory Browsing Support: {{{1
10820" ==========================================
10821
10822" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010823" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010824" Should accept: file://localhost/etc/fstab
10825" file:///etc/fstab
10826" file:///c:/WINDOWS/clock.avi
10827" file:///c|/WINDOWS/clock.avi
10828" file://localhost/c:/WINDOWS/clock.avi
10829" file://localhost/c|/WINDOWS/clock.avi
10830" file://c:/foo.txt
10831" file:///c:/foo.txt
10832" 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 +020010833fun! netrw#FileUrlEdit(fname)
10834" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 let fname = a:fname
10836 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010837" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010838 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010839" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010840 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010841 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010845" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846 endif
10847 endif
10848 let fname2396 = netrw#RFC2396(fname)
10849 let fname2396e= fnameescape(fname2396)
10850 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010851 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010854" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010855 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10856 endif
10857 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010858
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010859" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10860" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010861 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010862 exe 'NetrwKeepj keepalt edit '.plainfname
10863 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10864
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010865" 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 +020010866" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010867 exe "sil doau BufReadPost ".fname2396e
10868endfun
10869
10870" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010871" netrw#LocalBrowseCheck: {{{2
10872fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010873 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010874 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10875 "
10876 " unfortunate interaction -- split window debugging can't be used here, must use
10877 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10878 " another call to LocalBrowseCheck() when attempts to write
10879 " to the DBG buffer are made.
10880 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010881 " The &ft == "netrw" test was installed because the BufEnter event
10882 " would hit when re-entering netrw windows, creating unexpected
10883 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010884" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010885" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886" 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 +010010887 " getting E930: Cannot use :redir inside execute
10888"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010889" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10890" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010891
Bram Moolenaar97d62492012-11-15 21:28:22 +010010892 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893 if isdirectory(s:NetrwFile(a:dirname))
10894" 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 +010010895
Bram Moolenaar97d62492012-11-15 21:28:22 +010010896 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010897" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10898" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010899 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010900
Bram Moolenaar446cb832008-06-24 21:56:24 +000010901 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010902" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010903 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010904
Bram Moolenaar5c736222010-01-06 20:54:52 +010010905 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010907 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010908 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010910" 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 +010010911" call Dret("netrw#LocalBrowseCheck")
10912 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010913 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010914
Bram Moolenaar85850f32019-07-19 22:05:51 +020010915 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010916 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10917 " AND IF the listing style is not a tree listing
10918 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010919" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010920 let ibuf = 1
10921 let buflast = bufnr("$")
10922 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10924 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010925 endif
10926 let ibuf= ibuf + 1
10927 endwhile
10928 endif
10929 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010930" 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>"))
10931" 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 +000010932 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010933" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010934endfun
10935
10936" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010937" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010938" performed any shell command. The idea is to cause all local-browsing
10939" buffers to be refreshed after a user has executed some shell command,
10940" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010941fun! s:LocalBrowseRefresh()
10942" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010943" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10944" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010945
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 " determine which buffers currently reside in a tab
10947 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010948" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010949 return
10950 endif
10951 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010952" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953 return
10954 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010955 if !empty(getcmdwintype())
10956 " cannot move away from cmdline window, see :h E11
10957 return
10958 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010959 if exists("s:netrw_events") && s:netrw_events == 1
10960 " s:LocalFastBrowser gets called (indirectly) from a
10961 let s:netrw_events= 2
10962" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10963 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 let itab = 1
10966 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010967 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 while itab <= tabpagenr("$")
10969 let buftablist = buftablist + tabpagebuflist()
10970 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010971 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010973" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10974" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10976 " | refresh any netrw window
10977 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010978 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 let ibl = 0
10980 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010981" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10983 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010984 " (ibuf not shown in a current window AND
10985 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10987 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010990 continue
10991 elseif index(tabpagebuflist(),ibuf) != -1
10992 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010994 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010995 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010996 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10997 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10998 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10999 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011001 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11002 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11003 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011004 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005 endif
11006 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011007" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011008 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011009" call Decho("restore window: win_gotoid(".curwinid.")")
11010 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011011 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011012
Bram Moolenaara6878372014-03-22 21:02:50 +010011013" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011014endfun
11015
11016" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11018"
11019" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011020" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011021" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11022" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024"
11025" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11026" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011027" (re-using a buffer may not be as accurate)
11028"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011029" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011030" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11031" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11032" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11033" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011034fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011035" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11036" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11037" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11038" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011039
11040 " initialize browselist, a list of buffer numbers that the local browser has used
11041 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011042" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011043 let s:netrw_browselist= []
11044 endif
11045
11046 " append current buffer to fastbrowse list
11047 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011049 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011051 endif
11052
11053 " enable autocmd events to handle refreshing/removing local browser buffers
11054 " If local browse buffer is currently showing: refresh it
11055 " If local browse buffer is currently hidden : wipe it
11056 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11057 " =1 : medium speed, re-use directory listing for remote only
11058 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011059 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11060 let s:netrw_events= 1
11061 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011062 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011063 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011066 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011068 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011069 endif
11070 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071
11072 " user must have changed fastbrowse to its fast setting, so remove
11073 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011074 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011075" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011076 unlet s:netrw_events
11077 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078 au!
11079 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011080 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081 endif
11082
Bram Moolenaar85850f32019-07-19 22:05:51 +020011083" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011084endfun
11085
11086" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011087" s:LocalListing: does the job of "ls" for local directories {{{2
11088fun! s:LocalListing()
11089" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11091" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11092" 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 +010011093
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011094" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
11095" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist",'~'.expand("<slnum>"))|endif
11096" 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 +010011097
11098 " get the list of files contained in the current directory
11099 let dirname = b:netrw_curdir
11100 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011101 let filelist = s:NetrwGlob(dirname,"*",0)
11102 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011103" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011104
Nir Lichtman1e34b952024-05-08 19:19:34 +020011105 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11108 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011112 endif
11113
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011114" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011116" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011117
11118 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11119 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11120 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11122" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" 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 +010011125
11126 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho(" ",'~'.expand("<slnum>"))
11128" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129
11130 if getftype(filename) == "link"
11131 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011132" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011133 let pfile= filename."@"
11134
11135 elseif getftype(filename) == "socket"
11136 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 let pfile= filename."="
11139
11140 elseif getftype(filename) == "fifo"
11141 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011143 let pfile= filename."|"
11144
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011146 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 let pfile= filename."/"
11149
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011150 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011151 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11153 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011155 let pfile= filename."*"
11156 else
11157 " normal file
11158 let pfile= filename
11159 endif
11160 elseif executable(filename)
11161 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011162" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011163 let pfile= filename."*"
11164 else
11165 " normal file
11166 let pfile= filename
11167 endif
11168
11169 else
11170 " normal file
11171 let pfile= filename
11172 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011173" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011174
11175 if pfile =~ '//$'
11176 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011177" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011178 endif
11179 let pfile= strpart(pfile,dirnamelen)
11180 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011181" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11182" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011183
11184 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011185 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11186 let sz = getfsize(filename)
11187 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11188 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011189
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011190 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011191 let sz= s:NetrwHumanReadable(sz)
11192 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011193 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011194 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011195" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 endif
11197
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011198 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011200 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011201" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011202" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011204 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011205" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011207 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011208
11209 elseif g:netrw_sort_by =~ "^s"
11210 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011211" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011212" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011213 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011214 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011217 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011218
11219 else
11220 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011221" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011225" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011226 endfor
11227
11228 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011229 sil! NetrwKeepj g/^$/d
11230 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011231 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011232" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011233 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11234
11235" call Dret("s:LocalListing")
11236endfun
11237
11238" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011239" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11240fun! s:NetrwLocalExecute(cmd)
11241" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11242 let ykeep= @@
11243 " sanity check
11244 if !executable(a:cmd)
11245 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11246 let @@= ykeep
11247" call Dret("s:NetrwLocalExecute")
11248 return
11249 endif
11250
11251 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011252" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011253 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011254" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011255
11256 " strip any ansi escape sequences off
11257 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11258
11259 " show user the result(s)
11260 echomsg result
11261 let @@= ykeep
11262
11263" call Dret("s:NetrwLocalExecute")
11264endfun
11265
11266" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011267" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268fun! s:NetrwLocalRename(path) range
11269" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11270
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011271 if !exists("w:netrw_bannercnt")
11272 let w:netrw_bannercnt= b:netrw_bannercnt
11273 endif
11274
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011276 let ykeep = @@
11277 let ctr = a:firstline
11278 let svpos = winsaveview()
11279 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011280" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011281
11282 " rename files given by the markfilelist
11283 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11284 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011285" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011286 if exists("subfrom")
11287 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011288" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011289 else
11290 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011291 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011292 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011293 if newname =~ ''
11294 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11295 let newname = substitute(newname,'^.*','','')
11296 elseif newname =~ ''
11297 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11298 let newname = substitute(newname,'[^/]*','','')
11299 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011300 if newname =~ '^s/'
11301 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11302 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011303" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011304 let newname = substitute(oldname,subfrom,subto,'')
11305 endif
11306 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011307 if !all && filereadable(newname)
11308 call inputsave()
11309 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11310 call inputrestore()
11311 if response == "all"
11312 let all= 1
11313 elseif response != "y" && response != "yes"
11314 " refresh the directory
11315" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11316 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11317" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11318 NetrwKeepj call winrestview(svpos)
11319 let @@= ykeep
11320" call Dret("NetrwLocalRename")
11321 return
11322 endif
11323 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011324 call rename(oldname,newname)
11325 endfor
11326 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011327
Bram Moolenaar97d62492012-11-15 21:28:22 +010011328 else
11329
11330 " attempt to rename files/directories
11331 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011332 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011333
11334 " sanity checks
11335 if line(".") < w:netrw_bannercnt
11336 let ctr= ctr + 1
11337 continue
11338 endif
11339 let curword= s:NetrwGetWord()
11340 if curword == "./" || curword == "../"
11341 let ctr= ctr + 1
11342 continue
11343 endif
11344
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011345 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011346 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011347" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348
11349 call inputsave()
11350 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11351 call inputrestore()
11352
11353 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011354" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011355
11356 let ctr= ctr + 1
11357 endwhile
11358 endif
11359
11360 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011361" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011362 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011363" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11364 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011365 let @@= ykeep
11366
11367" call Dret("NetrwLocalRename")
11368endfun
11369
11370" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011371" s:NetrwLocalRm: {{{2
11372fun! s:NetrwLocalRm(path) range
11373" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011374" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011376 if !exists("w:netrw_bannercnt")
11377 let w:netrw_bannercnt= b:netrw_bannercnt
11378 endif
11379
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011381 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011382 let ret = 0
11383 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011384 let svpos = winsaveview()
11385" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386
11387 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11388 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011389" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390 for fname in s:netrwmarkfilelist_{bufnr("%")}
11391 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011392 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011394 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395 let all= 1
11396 endif
11397 endfor
11398 call s:NetrwUnMarkFile(1)
11399
11400 else
11401 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011402" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011403
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011404 let keepsol= &l:sol
11405 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406 let ctr = a:firstline
11407 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011408 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011409
11410 " sanity checks
11411 if line(".") < w:netrw_bannercnt
11412 let ctr= ctr + 1
11413 continue
11414 endif
11415 let curword= s:NetrwGetWord()
11416 if curword == "./" || curword == "../"
11417 let ctr= ctr + 1
11418 continue
11419 endif
11420 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011421 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011423 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011424 let all= 1
11425 endif
11426 let ctr= ctr + 1
11427 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011428 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429 endif
11430
11431 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011432" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011433 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011434 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011435" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11436 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011438 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439
11440" call Dret("s:NetrwLocalRm")
11441endfun
11442
11443" ---------------------------------------------------------------------
11444" s:NetrwLocalRmFile: remove file fname given the path {{{2
11445" Give confirmation prompt unless all==1
11446fun! s:NetrwLocalRmFile(path,fname,all)
11447" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011448
Bram Moolenaar446cb832008-06-24 21:56:24 +000011449 let all= a:all
11450 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011451 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011452 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011453" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011454
11455 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11456 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011457" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458 if !all
11459 echohl Statement
11460 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011461 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011462 call inputrestore()
11463 echohl NONE
11464 if ok == ""
11465 let ok="no"
11466 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011469" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011470 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011471 let all= 1
11472 endif
11473 endif
11474
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011475 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011476 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011477" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011478 endif
11479
11480 else
11481 " attempt to remove directory
11482 if !all
11483 echohl Statement
11484 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011485 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011486 call inputrestore()
11487 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11488 if ok == ""
11489 let ok="no"
11490 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011491 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011492 let all= 1
11493 endif
11494 endif
11495 let rmfile= substitute(rmfile,'[\/]$','','e')
11496
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011497 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011498 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011499 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011500 endif
11501 endif
11502 endif
11503
11504" call Dret("s:NetrwLocalRmFile ".ok)
11505 return ok
11506endfun
11507
Bram Moolenaar85850f32019-07-19 22:05:51 +020011508" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011509" Support Functions: {{{1
11510
Bram Moolenaar488c6512005-08-11 20:09:58 +000011511" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011512" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11513" 0: marked file list of current buffer
11514" 1: marked file target
11515fun! netrw#Access(ilist)
11516 if a:ilist == 0
11517 if exists("s:netrwmarkfilelist_".bufnr('%'))
11518 return s:netrwmarkfilelist_{bufnr('%')}
11519 else
11520 return "no-list-buf#".bufnr('%')
11521 endif
11522 elseif a:ilist == 1
11523 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011524 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011525endfun
11526
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011527" ---------------------------------------------------------------------
11528" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11529fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011530 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011531endfun
11532
Bram Moolenaara6878372014-03-22 21:02:50 +010011533" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011534" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11535" I expect this function to be used in
11536" :PChkAssert netrw#Expose("netrwmarkfilelist")
11537" for example.
11538fun! netrw#Expose(varname)
11539" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011540 if exists("s:".a:varname)
11541 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011542" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011543 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011544" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011545 if type(retval) == 3
11546 let retval = copy(retval)
11547 let i = 0
11548 while i < len(retval)
11549 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11550 let i = i + 1
11551 endwhile
11552 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011553" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011554 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011555 else
11556" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011557 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011558 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011559" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011560 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011561 endif
11562
11563" call Dret("netrw#Expose ".string(retval))
11564 return retval
11565endfun
11566
11567" ---------------------------------------------------------------------
11568" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11569fun! netrw#Modify(varname,newvalue)
11570" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11571 exe "let s:".a:varname."= ".string(a:newvalue)
11572" call Dret("netrw#Modify")
11573endfun
11574
11575" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011576" netrw#RFC2396: converts %xx into characters {{{2
11577fun! netrw#RFC2396(fname)
11578" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011579 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011580" call Dret("netrw#RFC2396 ".fname)
11581 return fname
11582endfun
11583
11584" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011585" netrw#UserMaps: supports user-specified maps {{{2
11586" see :help function()
11587"
11588" g:Netrw_UserMaps is a List with members such as:
11589" [[keymap sequence, function reference],...]
11590"
11591" The referenced function may return a string,
11592" refresh : refresh the display
11593" -other- : this string will be executed
11594" or it may return a List of strings.
11595"
11596" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011597" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011598" Related functions:
11599" netrw#Expose(varname) -- see s:varname variables
11600" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11601" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11602fun! netrw#UserMaps(islocal)
11603" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11604" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11605
11606 " set up usermaplist
11607 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11608" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11609 for umap in g:Netrw_UserMaps
11610" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11611" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11612 " if umap[0] is a string and umap[1] is a string holding a function name
11613 if type(umap[0]) == 1 && type(umap[1]) == 1
11614" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11615 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11616 else
11617 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11618 endif
11619 endfor
11620 endif
11621" call Dret("netrw#UserMaps")
11622endfun
11623
11624" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011625" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11626fun! netrw#WinPath(path)
11627" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011628 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011629 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011630 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011631 " remove trailing slash (Win95)
11632 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11633 " remove escaped spaces
11634 let path = substitute(path, '\ ', ' ', 'g')
11635 " convert slashes to backslashes
11636 let path = substitute(path, '/', '\', 'g')
11637 else
11638 let path= a:path
11639 endif
11640" call Dret("netrw#WinPath <".path.">")
11641 return path
11642endfun
11643
11644" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011645" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11646fun! s:StripTrailingSlash(path)
11647 " remove trailing slash
11648 return substitute(a:path, '[/\\]$', '', 'g')
11649endfun
11650
Travis Sheltone34d0e32024-07-30 21:08:56 +020011651" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011652" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11653" cb : bl2mf=0 add marked files to buffer list
11654" cB : bl2mf=1 use bufferlist to mark files
11655" (mnemonic: cb = copy (marked files) to buffer list)
11656fun! s:NetrwBadd(islocal,bl2mf)
11657" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11658 if a:bl2mf
11659 " cB: add buffer list to marked files
11660 redir => bufl
11661 ls
11662 redir END
11663 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11664 for fname in bufl
11665 call s:NetrwMarkFile(a:islocal,fname)
11666 endfor
11667 else
11668 " cb: add marked files to buffer list
11669 for fname in s:netrwmarkfilelist_{bufnr("%")}
11670" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11671 exe "badd ".fnameescape(fname)
11672 endfor
11673 let curbufnr = bufnr("%")
11674 let curdir = s:NetrwGetCurdir(a:islocal)
11675 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11676 endif
11677" call Dret("s:NetrwBadd")
11678endfun
11679
11680" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011681" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11682fun! s:ComposePath(base,subdir)
11683" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11684
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011685 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011687 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011689 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011691 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011692 endif
11693
Bram Moolenaar85850f32019-07-19 22:05:51 +020011694 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011695 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011696" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011697 let ret= a:subdir
11698
Nir Lichtman1e34b952024-05-08 19:19:34 +020011699 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011701 if a:base =~ '[/\\]$'
11702 let ret= a:base.a:subdir
11703 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011705 endif
11706
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707 elseif a:base =~ '^\a\{3,}://'
11708" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011709 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11710 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11711 if a:subdir == '../'
11712 if curpath =~ '[^/]/[^/]\+/$'
11713 let curpath= substitute(curpath,'[^/]\+/$','','')
11714 else
11715 let curpath=""
11716 endif
11717 let ret= urlbase.curpath
11718 else
11719 let ret= urlbase.curpath.a:subdir
11720 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011721" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11722" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11723" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011724
11725 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011726" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011727 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11728 if a:base =~ '^//'
11729 " keeping initial '//' for the benefit of network share listing support
11730 let ret= '/'.ret
11731 endif
11732 let ret= simplify(ret)
11733 endif
11734
11735" call Dret("s:ComposePath ".ret)
11736 return ret
11737endfun
11738
11739" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011740" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11741" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11742fun! s:DeleteBookmark(fname)
11743" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11744 call s:MergeBookmarks()
11745
11746 if exists("g:netrw_bookmarklist")
11747 let indx= index(g:netrw_bookmarklist,a:fname)
11748 if indx == -1
11749 let indx= 0
11750 while indx < len(g:netrw_bookmarklist)
11751 if g:netrw_bookmarklist[indx] =~ a:fname
11752 call remove(g:netrw_bookmarklist,indx)
11753 let indx= indx - 1
11754 endif
11755 let indx= indx + 1
11756 endwhile
11757 else
11758 " remove exact match
11759 call remove(g:netrw_bookmarklist,indx)
11760 endif
11761 endif
11762
11763" call Dret("s:DeleteBookmark")
11764endfun
11765
11766" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767" s:FileReadable: o/s independent filereadable {{{2
11768fun! s:FileReadable(fname)
11769" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11770
11771 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011772 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011773 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011774 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775 endif
11776
11777" call Dret("s:FileReadable ".ret)
11778 return ret
11779endfun
11780
11781" ---------------------------------------------------------------------
11782" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11783" Places correct suffix on end of temporary filename,
11784" using the suffix provided with fname
11785fun! s:GetTempfile(fname)
11786" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11787
11788 if !exists("b:netrw_tmpfile")
11789 " get a brand new temporary filename
11790 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011791" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011792
Bram Moolenaarc236c162008-07-13 17:41:49 +000011793 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011794" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011795
Bram Moolenaar9964e462007-05-05 17:54:07 +000011796 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11798" 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 +010011799 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011800" call Dret("s:GetTempfile getcwd<".getcwd().">")
11801 return ""
11802 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011803
Bram Moolenaar9964e462007-05-05 17:54:07 +000011804 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011805 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011806" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011810 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011811 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011812 if !exists("+shellslash") || !&ssl
11813 let tmpfile = substitute(tmpfile,'/','\','g')
11814 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 endif
11818 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011819" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820 else
11821 " re-use temporary filename
11822 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011823" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 endif
11825
11826 " use fname's suffix for the temporary file
11827 if a:fname != ""
11828 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011830 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011832 elseif a:fname =~ '.txz$'
11833 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011834 else
11835 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011838 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011839" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011841" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011842 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11843 endif
11844 endif
11845
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011846" 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 +000011847" call Dret("s:GetTempfile <".tmpfile.">")
11848 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011849endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011850
11851" ---------------------------------------------------------------------
11852" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011853" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011855" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011856 if s:user == ""
11857 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11858 else
11859 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11860 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011861 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011862 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011863 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011864 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011865 else
11866 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11867 endif
11868" call Dret("s:MakeSshCmd <".sshcmd.">")
11869 return sshcmd
11870endfun
11871
11872" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011873" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11874fun! s:MakeBookmark(fname)
11875" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11876
11877 if !exists("g:netrw_bookmarklist")
11878 let g:netrw_bookmarklist= []
11879 endif
11880
11881 if index(g:netrw_bookmarklist,a:fname) == -1
11882 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011883 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011884 call add(g:netrw_bookmarklist,a:fname.'/')
11885 elseif a:fname !~ '/'
11886 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11887 else
11888 call add(g:netrw_bookmarklist,a:fname)
11889 endif
11890 call sort(g:netrw_bookmarklist)
11891 endif
11892
11893" call Dret("s:MakeBookmark")
11894endfun
11895
11896" ---------------------------------------------------------------------
11897" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11898fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011899" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011900 " get bookmarks from .netrwbook file
11901 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902 if filereadable(s:NetrwFile(savefile))
11903" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011904 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011905" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011906 NetrwKeepj call delete(savefile)
11907 endif
11908" call Dret("s:MergeBookmarks")
11909endfun
11910
11911" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011912" s:NetrwBMShow: {{{2
11913fun! s:NetrwBMShow()
11914" call Dfunc("s:NetrwBMShow()")
11915 redir => bmshowraw
11916 menu
11917 redir END
11918 let bmshowlist = split(bmshowraw,'\n')
11919 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011920 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921 if bmshowfuncs != []
11922 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011923 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011924 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011926 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011927 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011928" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11929endfun
11930
11931" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011932" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011933fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011934 if !exists("w:netrw_liststyle")
11935 let w:netrw_liststyle= g:netrw_liststyle
11936 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011937" 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 +020011938
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011939" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11940
Bram Moolenaaradc21822011-04-01 18:03:16 +020011941 if &ft != "netrw"
11942 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11943 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011944" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011945
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011946 elseif g:netrw_cursor == 8
11947 if w:netrw_liststyle == s:WIDELIST
11948 setl cursorline
11949 setl cursorcolumn
11950 else
11951 setl cursorline
11952 endif
11953 elseif g:netrw_cursor == 7
11954 setl cursorline
11955 elseif g:netrw_cursor == 6
11956 if w:netrw_liststyle == s:WIDELIST
11957 setl cursorline
11958 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011959 elseif g:netrw_cursor == 4
11960 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011962 setl cursorline
11963 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011964
11965 elseif g:netrw_cursor == 3
11966 " thin-long-tree: cursorline, user's cursorcolumn
11967 " wide : cursorline, cursorcolumn
11968 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011970 setl cursorline
11971 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" 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 +020011974 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975 endif
11976
11977 elseif g:netrw_cursor == 2
11978 " thin-long-tree: cursorline, user's cursorcolumn
11979 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011981 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982
11983 elseif g:netrw_cursor == 1
11984 " thin-long-tree: user's cursorline, user's cursorcolumn
11985 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011987" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011988 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011990" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011991 endif
11992
11993 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011995" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011996 let &l:cursorline = s:netrw_usercul
11997 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011998 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011999
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012000" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012002endfun
12003
12004" ---------------------------------------------------------------------
12005" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12006fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012007" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012008 if exists("s:netrw_usercul")
12009 let &l:cursorline = s:netrw_usercul
12010 endif
12011 if exists("s:netrw_usercuc")
12012 let &l:cursorcolumn = s:netrw_usercuc
12013 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012014" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012015" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12016endfun
12017
Christian Brabandt62f7b552024-06-23 20:23:40 +020012018" s:RestoreRegister: restores all registers given in the dict {{{2
12019fun! s:RestoreRegister(dict)
12020 for [key, val] in items(a:dict)
12021 if key == 'unnamed'
12022 let key = ''
12023 endif
12024 call setreg(key, val[0], val[1])
12025 endfor
12026endfun
12027
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012028" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012029" s:NetrwDelete: Deletes a file. {{{2
12030" Uses Steve Hall's idea to insure that Windows paths stay
12031" acceptable. No effect on Unix paths.
12032" Examples of use: let result= s:NetrwDelete(path)
12033fun! s:NetrwDelete(path)
12034" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12035
Bram Moolenaar5c736222010-01-06 20:54:52 +010012036 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012037 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012038 if exists("+shellslash")
12039 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012040 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012041 let result = delete(path)
12042 let &shellslash = sskeep
12043 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012044" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012045 let result= delete(path)
12046 endif
12047 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012048" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012049 let result= delete(path)
12050 endif
12051 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012052 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012053 endif
12054
12055" call Dret("s:NetrwDelete ".result)
12056 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012057endfun
12058
12059" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012060" s:NetrwBufRemover: removes a buffer that: {{{2s
12061" has buffer-id > 1
12062" is unlisted
12063" is unnamed
12064" does not appear in any window
12065fun! s:NetrwBufRemover(bufid)
12066" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12067" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12068" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12069" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12070" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12071
yasuda4dbb2662023-10-04 20:50:35 +020012072 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012073" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012074 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012075 endif
12076
12077" call Dret("s:NetrwBufRemover")
12078endfun
12079
12080" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012081" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012082fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012083" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012084" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012085
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012086 " Clean out the last buffer:
12087 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12088 " If so, delete it.
12089 call s:NetrwBufRemover(bufnr("$"))
12090
Bram Moolenaar446cb832008-06-24 21:56:24 +000012091 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012092" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012093 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12094 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12095 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12096 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12097 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12098 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12099 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12100 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12101 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12102 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12103 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12104 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12105 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12106 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12107 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12108 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12109
Bram Moolenaar85850f32019-07-19 22:05:51 +020012110 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012111" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012112 " when tree listing uses file TreeListing... a new buffer is made.
12113 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012114 " COMBAK: this causes a problem, see P43
12115" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012116 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012117 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012118 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012119" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012120 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012121
Bram Moolenaar446cb832008-06-24 21:56:24 +000012122 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012123" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012124 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12125 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12126 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12127 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12128 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12129 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12130 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12131 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12132 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12133 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12134 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12135 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12136 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12137 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12138 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12139 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12140
Bram Moolenaar5c736222010-01-06 20:54:52 +010012141 if a:0 > 0
12142 let b:netrw_curdir= a:1
12143 if b:netrw_curdir =~ '/$'
12144 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012145 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012146 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012147 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012148 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12149 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012150 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012151 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012152 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012153 endif
12154 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012155 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12156 let &l:bexpr = "netrw#BalloonHelp()"
12157 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012158
Bram Moolenaar8d043172014-01-23 14:24:41 +010012159" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012160endfun
12161
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012162" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012163" s:NetrwExe: executes a string using "!" {{{2
12164fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012165" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012166 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012167" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012168 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12169 set shell& shellcmdflag& shellxquote& shellxescape&
12170 set shellquote& shellpipe& shellredir& shellslash&
12171 exe a:cmd
12172 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12173 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012174" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012175 exe a:cmd
12176 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012177 if v:shell_error
12178 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12179 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012180" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012181endfun
12182
12183" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12185fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012186 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012187" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012188 let curbuf = bufnr("%")
12189 let curwin = winnr()
12190 let iwin = 1
12191 while iwin <= winnr("$")
12192 exe iwin."wincmd w"
12193 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12194 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12195 let winvars= w:
12196 break
12197 endif
12198 let iwin= iwin + 1
12199 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012200 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012201 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012202" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012203 for k in keys(winvars)
12204 let w:{k}= winvars[k]
12205 endfor
12206 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012207" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012208 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012209endfun
12210
Bram Moolenaara6878372014-03-22 21:02:50 +010012211" ---------------------------------------------------------------------
12212" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012213" Returns: 0=success
12214" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012215fun! s:NetrwLcd(newdir)
12216" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012217" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012218
Bram Moolenaar85850f32019-07-19 22:05:51 +020012219 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012220 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012221 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 catch /^Vim\%((\a\+)\)\=:E344/
12223 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12224 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012225 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012226 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12227 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012228 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12230 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012231 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012232 endif
12233 endif
12234 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012235 let err472= 1
12236 endtry
12237
12238 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012239 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12240 if exists("w:netrw_prvdir")
12241 let a:newdir= w:netrw_prvdir
12242 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012243 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012244" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012245 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012246" 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 +010012247 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012249" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12250 return -1
12251 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012252
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012253" call Decho("getcwd <".getcwd().">")
12254" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012255" call Dret("s:NetrwLcd 0")
12256 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012257endfun
12258
Bram Moolenaar9964e462007-05-05 17:54:07 +000012259" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012260" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12261" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12262fun! s:NetrwSaveWordPosn()
12263" call Dfunc("NetrwSaveWordPosn()")
12264 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12265" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12266endfun
12267
12268" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012269" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12270" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12271fun! s:NetrwHumanReadable(sz)
12272" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12273
12274 if g:netrw_sizestyle == 'h'
12275 if a:sz >= 1000000000
12276 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12277 elseif a:sz >= 10000000
12278 let sz = printf("%d",a:sz/1000000)."m"
12279 elseif a:sz >= 1000000
12280 let sz = printf("%.1f",a:sz/1000000.0)."m"
12281 elseif a:sz >= 10000
12282 let sz = printf("%d",a:sz/1000)."k"
12283 elseif a:sz >= 1000
12284 let sz = printf("%.1f",a:sz/1000.0)."k"
12285 else
12286 let sz= a:sz
12287 endif
12288
12289 elseif g:netrw_sizestyle == 'H'
12290 if a:sz >= 1073741824
12291 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12292 elseif a:sz >= 10485760
12293 let sz = printf("%d",a:sz/1048576)."M"
12294 elseif a:sz >= 1048576
12295 let sz = printf("%.1f",a:sz/1048576.0)."M"
12296 elseif a:sz >= 10240
12297 let sz = printf("%d",a:sz/1024)."K"
12298 elseif a:sz >= 1024
12299 let sz = printf("%.1f",a:sz/1024.0)."K"
12300 else
12301 let sz= a:sz
12302 endif
12303
12304 else
12305 let sz= a:sz
12306 endif
12307
12308" call Dret("s:NetrwHumanReadable ".sz)
12309 return sz
12310endfun
12311
12312" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012313" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12314" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12315fun! s:NetrwRestoreWordPosn()
12316" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012317 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012318" call Dret("NetrwRestoreWordPosn")
12319endfun
12320
12321" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012322" s:RestoreBufVars: {{{2
12323fun! s:RestoreBufVars()
12324" call Dfunc("s:RestoreBufVars()")
12325
12326 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12327 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12328 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12329 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12330 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12331 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12332
12333" call Dret("s:RestoreBufVars")
12334endfun
12335
12336" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012337" s:RemotePathAnalysis: {{{2
12338fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012339" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012340
Bram Moolenaara6878372014-03-22 21:02:50 +010012341 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012342 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012343 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012344 let s:user = substitute(a:dirname,dirpat,'\3','')
12345 let s:machine = substitute(a:dirname,dirpat,'\4','')
12346 let s:port = substitute(a:dirname,dirpat,'\5','')
12347 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012348 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012349 if s:machine =~ '@'
12350 let dirpat = '^\(.*\)@\(.\{-}\)$'
12351 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12352 let s:machine = substitute(s:machine,dirpat,'\2','')
12353 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012354
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012355" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12356" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12357" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12358" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12359" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12360" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012361
12362" call Dret("s:RemotePathAnalysis")
12363endfun
12364
12365" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012366" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12367" Returns status
12368" Runs system() on
12369" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012370" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012371fun! s:RemoteSystem(cmd)
12372" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12373 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012374 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 +000012375 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012376 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012377 else
12378 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12379 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12380 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012381 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012382 else
12383 let cmd= cmd.' '
12384 endif
12385 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012386" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012387 let ret= system(cmd)
12388 endif
12389" call Dret("s:RemoteSystem ".ret)
12390 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012391endfun
12392
12393" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012394" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012395fun! s:RestoreWinVars()
12396" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012397 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012398 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12399 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12400 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12401 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12402 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12403 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12404 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12405 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12406 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12407 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12408 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12409 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012410 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12411 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012412 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12413 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12414 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12415" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012416endfun
12417
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012418" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012419" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12420"
12421" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12422" is true) and a command, :Rexplore, which call this function.
12423"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012424" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012425"
12426" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012427fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012428 if exists("s:netrwdrag")
12429 return
12430 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012431" 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 +010012432" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12433" 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 +010012434
12435 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012436 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012437" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012438 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012439 unlet w:netrw_rexfile
12440" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012441 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012442" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012443" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12444" 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 +020012445 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012446
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012447 " ---------------------------
12448 " :Rex issued while in a file
12449 " ---------------------------
12450
Bram Moolenaara6878372014-03-22 21:02:50 +010012451 " record current file so :Rex can return to it from netrw
12452 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012453" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012454
12455 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012456" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012457 return
12458 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459" 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 +020012460 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012461 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012462 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012463 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012464 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012465 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012466 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012467 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012468 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012469" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12470 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012471" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12472 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012473 if exists("s:rexposn_".bufnr('%'))
12474 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012475 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012476 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012477" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012478 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012479
Bram Moolenaar85850f32019-07-19 22:05:51 +020012480 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12481 if exists("s:explore_match")
12482 exe "2match netrwMarkFile /".s:explore_match."/"
12483 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012484 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012485
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012486" 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 +010012487" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012488endfun
12489
12490" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012491" s:SaveBufVars: save selected b: variables to s: variables {{{2
12492" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012493fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012494" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012495
12496 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12497 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12498 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12499 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12500 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12501 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12502
12503" call Dret("s:SaveBufVars")
12504endfun
12505
12506" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012507" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12508fun! s:SavePosn(posndict)
12509" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12510
Bram Moolenaar85850f32019-07-19 22:05:51 +020012511 if !exists("a:posndict[bufnr('%')]")
12512 let a:posndict[bufnr("%")]= []
12513 endif
12514" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12515 call add(a:posndict[bufnr("%")],winsaveview())
12516" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012517
12518" call Dret("s:SavePosn posndict")
12519 return a:posndict
12520endfun
12521
12522" ---------------------------------------------------------------------
12523" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12524fun! s:RestorePosn(posndict)
12525" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012526 if exists("a:posndict")
12527 if has_key(a:posndict,bufnr("%"))
12528" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12529 let posnlen= len(a:posndict[bufnr("%")])
12530 if posnlen > 0
12531 let posnlen= posnlen - 1
12532" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12533 call winrestview(a:posndict[bufnr("%")][posnlen])
12534 call remove(a:posndict[bufnr("%")],posnlen)
12535" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12536 endif
12537 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012538 endif
12539" call Dret("s:RestorePosn")
12540endfun
12541
12542" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012543" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012544fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012545" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012546 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12547 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12548 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12549 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12550 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12551 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12552 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12553 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12554 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12555 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12556 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12557 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12558 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12559 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12560 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12561 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12562 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12563 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12564" call Dret("s:SaveWinVars")
12565endfun
12566
12567" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012568" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012569" To allow separate windows to have their own activities, such as
12570" Explore **/pattern, several variables have been made window-oriented.
12571" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012572" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012573" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012574fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012575" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012576 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12577 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12578 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12579 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12580 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12581 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12582 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12583 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12584 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12585 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12586" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012587endfun
12588
12589" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012590" s:SetRexDir: set directory for :Rexplore {{{2
12591fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012592" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012593 let w:netrw_rexdir = a:dirname
12594 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012595 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012596" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12597" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012598" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012599" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012600" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012601endfun
12602
12603" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012604" s:ShowLink: used to modify thin and tree listings to show links {{{2
12605fun! s:ShowLink()
12606" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012607" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12608" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012609 if exists("b:netrw_curdir")
12610 norm! $?\a
12611 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12612 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012613" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12614" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12615" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12616 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012617 let dirlen = strlen(b:netrw_curdir)
12618 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012619" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012620 endif
12621 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012622" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12623" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012624 setl noro ma
12625 call setline(".",modline)
12626 setl ro noma nomod
12627 endif
12628" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12629endfun
12630
12631" ---------------------------------------------------------------------
12632" s:ShowStyle: {{{2
12633fun! s:ShowStyle()
12634 if !exists("w:netrw_liststyle")
12635 let liststyle= g:netrw_liststyle
12636 else
12637 let liststyle= w:netrw_liststyle
12638 endif
12639 if liststyle == s:THINLIST
12640 return s:THINLIST.":thin"
12641 elseif liststyle == s:LONGLIST
12642 return s:LONGLIST.":long"
12643 elseif liststyle == s:WIDELIST
12644 return s:WIDELIST.":wide"
12645 elseif liststyle == s:TREELIST
12646 return s:TREELIST.":tree"
12647 else
12648 return 'n/a'
12649 endif
12650endfun
12651
12652" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012653" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12654" Solution from Nicolai Weibull, vim docs (:help strlen()),
12655" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012656fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012657" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12658
12659 if v:version >= 703 && exists("*strdisplaywidth")
12660 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012661
Bram Moolenaar8d043172014-01-23 14:24:41 +010012662 elseif type(g:Align_xstrlen) == 1
12663 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12664 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012665
Bram Moolenaar8d043172014-01-23 14:24:41 +010012666 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012667 " number of codepoints (Latin a + combining circumflex is two codepoints)
12668 " (comment from TM, solution from NW)
12669 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012670
Bram Moolenaar8d043172014-01-23 14:24:41 +010012671 elseif g:Align_xstrlen == 2
12672 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012673 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12674 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012676
Bram Moolenaar8d043172014-01-23 14:24:41 +010012677 elseif g:Align_xstrlen == 3
12678 " virtual length (counting, for instance, tabs as anything between 1 and
12679 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012680 " preceded by lam, one otherwise, etc.)
12681 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012682 let modkeep= &l:mod
12683 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012684 call setline(line("."),a:x)
12685 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012686 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012687 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012688 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012689
Bram Moolenaar446cb832008-06-24 21:56:24 +000012690 else
12691 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012692 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012693 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012694" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012695 return ret
12696endfun
12697
12698" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012699" s:ShellEscape: shellescape(), or special windows handling {{{2
12700fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012701 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012702 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12703 endif
12704 let f = a:0 > 0 ? a:1 : 0
12705 return shellescape(a:s, f)
12706endfun
12707
12708" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012709" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012710fun! s:TreeListMove(dir)
12711" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012712 let curline = getline('.')
12713 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12714 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12715 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12716 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12717 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12718 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12719" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12720" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12721" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12722" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12723" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12724 " COMBAK : need to handle when on a directory
12725 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012726 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012727 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012728 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012729 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012730" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012731 elseif a:dir == '[]' && nxtline != ''
12732 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012733" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012734 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12735 if nl != 0
12736 NetrwKeepj norm! k
12737 else
12738 NetrwKeepj norm! G
12739 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012740" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012741 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012742 endif
12743
12744" call Dret("s:TreeListMove")
12745endfun
12746
12747" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012748" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12749" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12750" can't be called except via emenu. But due to locale, that menu line may not be called
12751" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12752fun! s:UpdateBuffersMenu()
12753" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012754 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012755 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012756 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012757 catch /^Vim\%((\a\+)\)\=:E/
12758 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012759 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012760 endtry
12761 endif
12762" call Dret("s:UpdateBuffersMenu")
12763endfun
12764
12765" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012766" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012767" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012768fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012769" call Dfunc("s:UseBufWinVars()")
12770 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012771 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12772 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12773 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12774 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12775 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12776 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12777 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12778 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12779 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 +000012780" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012781endfun
12782
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012783" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012784" s:UserMaps: supports user-defined UserMaps {{{2
12785" * calls a user-supplied funcref(islocal,curdir)
12786" * interprets result
12787" See netrw#UserMaps()
12788fun! s:UserMaps(islocal,funcname)
12789" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12790
12791 if !exists("b:netrw_curdir")
12792 let b:netrw_curdir= getcwd()
12793 endif
12794 let Funcref = function(a:funcname)
12795 let result = Funcref(a:islocal)
12796
12797 if type(result) == 1
12798 " if result from user's funcref is a string...
12799" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12800 if result == "refresh"
12801" call Decho("refreshing display",'~'.expand("<slnum>"))
12802 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12803 elseif result != ""
12804" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12805 exe result
12806 endif
12807
12808 elseif type(result) == 3
12809 " if result from user's funcref is a List...
12810" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12811 for action in result
12812 if action == "refresh"
12813" call Decho("refreshing display",'~'.expand("<slnum>"))
12814 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12815 elseif action != ""
12816" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12817 exe action
12818 endif
12819 endfor
12820 endif
12821
12822" call Dret("s:UserMaps")
12823endfun
12824
Bram Moolenaar85850f32019-07-19 22:05:51 +020012825" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012826" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012827" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012828let &cpo= s:keepcpo
12829unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012830
Bram Moolenaar85850f32019-07-19 22:05:51 +020012831" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012832" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012833" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012834" vim:ts=8 fdm=marker