blob: 0adcc6586952ec51888c4542af633cecea1bd03d [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Travis Sheltone34d0e32024-07-30 21:08:56 +020030" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010031" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000032" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010033" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000034" Permission is hereby granted to use and distribute this code,
35" with or without modifications, provided that this copyright
36" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000037" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000038" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000039" expressed or implied. By using this plugin, you agree that
40" in no event will the copyright holder be liable for any damages
41" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010042"
43" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
44" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
45"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020046"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000047"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000048" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" (James 1:22 RSV)
50" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000051" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000052if &cp || exists("g:loaded_netrw")
53 finish
54endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020055
56" Check that vim has patches that netrw requires.
57" Patches needed for v7.4: 1557, and 213.
58" (netrw will benefit from vim's having patch#656, too)
59let s:needspatches=[1557,213]
60if exists("s:needspatches")
61 for ptch in s:needspatches
62 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
63 if !exists("s:needpatch{ptch}")
64 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
65 endif
66 let s:needpatch{ptch}= 1
67 finish
68 endif
69 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020070endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020071
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010072let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000073
Bram Moolenaar1afcace2005-11-25 19:54:28 +000074let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010075setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020076"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010077"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010078"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000079
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000080" ======================
81" Netrw Variables: {{{1
82" ======================
83
Bram Moolenaar071d4272004-06-13 20:20:40 +000084" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020085" netrw#ErrorMsg: {{{2
86" 0=note = s:NOTE
87" 1=warning = s:WARNING
88" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010089" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
90" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
91" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010092" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020093fun! netrw#ErrorMsg(level,msg,errnum)
94" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
95
96 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020097" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020098 return
99 endif
100
101 if a:level == 1
102 let level= "**warning** (netrw) "
103 elseif a:level == 2
104 let level= "**error** (netrw) "
105 else
106 let level= "**note** (netrw) "
107 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100108" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200109
Damienb4d11642024-08-15 22:00:45 +0200110 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200111 " use popup window
112 if type(a:msg) == 3
113 let msg = [level]+a:msg
114 else
115 let msg= level.a:msg
116 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200117 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200118 let s:popuperr_text= ""
119 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120 " (default) netrw creates a one-line window to show error/warning
121 " messages (reliably displayed)
122
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100123 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100125" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126
127 " getting messages out reliably is just plain difficult!
128 " This attempt splits the current window, creating a one line window.
129 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100132" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100134 if type(a:msg) == 3
135 for msg in a:msg
136 NetrwKeepj call setline(line("$")+1,level.msg)
137 endfor
138 else
139 NetrwKeepj call setline(line("$")+1,level.a:msg)
140 endif
141 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100143" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 bo 1split
145 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200146 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100148 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100149" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100151 if type(a:msg) == 3
152 for msg in a:msg
153 NetrwKeepj call setline(line("$")+1,level.msg)
154 endfor
155 else
156 NetrwKeepj call setline(line("$"),level.a:msg)
157 endif
158 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200159 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100160" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200161 if &fo !~ '[ta]'
162 syn clear
163 syn match netrwMesgNote "^\*\*note\*\*"
164 syn match netrwMesgWarning "^\*\*warning\*\*"
165 syn match netrwMesgError "^\*\*error\*\*"
166 hi link netrwMesgWarning WarningMsg
167 hi link netrwMesgError Error
168 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100169" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200170 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200171
172 else
173 " (optional) netrw will show messages using echomsg. Even if the
174 " message doesn't appear, at least it'll be recallable via :messages
175" redraw!
176 if a:level == s:WARNING
177 echohl WarningMsg
178 elseif a:level == s:ERROR
179 echohl Error
180 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100181
182 if type(a:msg) == 3
183 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100184 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100185 endfor
186 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100187 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100188 endif
189
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100190" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200191 echohl None
192 endif
193
194" call Dret("netrw#ErrorMsg")
195endfun
196
197" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100198" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100199" Loosely, varname = value.
200fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100201" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100202 if !exists(a:varname)
203 if type(a:value) == 0
204 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200205 elseif type(a:value) == 1 && a:value =~ '^[{[]'
206 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100207 elseif type(a:value) == 1
208 exe "let ".a:varname."="."'".a:value."'"
209 else
210 exe "let ".a:varname."=".a:value
211 endif
212 endif
213endfun
214
215" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000216" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200217call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000218if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100219 call s:NetrwInit("s:THINLIST",0)
220 call s:NetrwInit("s:LONGLIST",1)
221 call s:NetrwInit("s:WIDELIST",2)
222 call s:NetrwInit("s:TREELIST",3)
223 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000224endif
225
Damien7c754112024-08-15 21:58:57 +0200226let s:NOTE = 0
227let s:WARNING = 1
228let s:ERROR = 2
229call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
230
Bram Moolenaar9964e462007-05-05 17:54:07 +0000231" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200232" Default option values: {{{2
233let g:netrw_localcopycmdopt = ""
234let g:netrw_localcopydircmdopt = ""
235let g:netrw_localmkdiropt = ""
236let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200237
238" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000239" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200240if exists("*popup_atcursor")
241\ && has("syntax")
242\ && exists("g:syntax_on")
243\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200244 call s:NetrwInit("g:netrw_use_errorwindow",2)
245else
246 call s:NetrwInit("g:netrw_use_errorwindow",1)
247endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200248
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000249if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100250 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000251 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100252 elseif executable("curl")
253 let g:netrw_dav_cmd = "curl"
254 else
255 let g:netrw_dav_cmd = ""
256 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000258if !exists("g:netrw_fetch_cmd")
259 if executable("fetch")
260 let g:netrw_fetch_cmd = "fetch -o"
261 else
262 let g:netrw_fetch_cmd = ""
263 endif
264endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100265if !exists("g:netrw_file_cmd")
266 if executable("elinks")
267 call s:NetrwInit("g:netrw_file_cmd","elinks")
268 elseif executable("links")
269 call s:NetrwInit("g:netrw_file_cmd","links")
270 endif
271endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000272if !exists("g:netrw_ftp_cmd")
273 let g:netrw_ftp_cmd = "ftp"
274endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200275let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200276if !exists("g:netrw_ftp_options")
277 let g:netrw_ftp_options= "-i -n"
278endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000279if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100280 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100281 let g:netrw_http_cmd = "wget"
282 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100283 elseif executable("curl")
284 let g:netrw_http_cmd = "curl"
285 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200286 elseif executable("elinks")
287 let g:netrw_http_cmd = "elinks"
288 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000289 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100290 let g:netrw_http_cmd = "fetch"
291 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200292 elseif executable("links")
293 let g:netrw_http_cmd = "links"
294 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000295 else
296 let g:netrw_http_cmd = ""
297 endif
298endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100299call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100300call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100301call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
302call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200303call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200304if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200305 if executable("scp")
306 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
307 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200308 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200309 else
310 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
311 endif
312endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100313call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
314call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000315
Nir Lichtman1e34b952024-05-08 19:19:34 +0200316if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000317 \ && exists("g:netrw_use_nt_rcp")
318 \ && g:netrw_use_nt_rcp
319 \ && executable( $SystemRoot .'/system32/rcp.exe')
320 let s:netrw_has_nt_rcp = 1
321 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000322else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000323 let s:netrw_has_nt_rcp = 0
324 let s:netrw_rcpmode = ''
325endif
326
327" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000328" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000329" Cygwin Detection ------- {{{3
330if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200331 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
332 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000333 else
334 let g:netrw_cygwin= 0
335 endif
336endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000337" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100338call s:NetrwInit("g:netrw_alto" , &sb)
339call s:NetrwInit("g:netrw_altv" , &spr)
340call s:NetrwInit("g:netrw_banner" , 1)
341call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200342call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200344call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_compress" , "gzip")
346call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200347if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
348 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
349 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000350endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200351call s:NetrwInit("g:netrw_cursor" , 2)
352let s:netrw_usercul = &cursorline
353let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200354"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100355call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000356" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200357call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200358call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200359call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360call s:NetrwInit("g:netrw_dirhistmax" , 10)
361call s:NetrwInit("g:netrw_fastbrowse" , 1)
362call 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 +0000363if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000364 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
365 let g:netrw_ftp_list_cmd = "ls -lF"
366 let g:netrw_ftp_timelist_cmd = "ls -tlF"
367 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000368 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000369 let g:netrw_ftp_list_cmd = "dir"
370 let g:netrw_ftp_timelist_cmd = "dir"
371 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000372 endif
373endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100374call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000375" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100376call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377if !exists("g:netrw_ignorenetrc")
378 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
379 let g:netrw_ignorenetrc= 1
380 else
381 let g:netrw_ignorenetrc= 0
382 endif
383endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100384call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000385if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000386 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100387 if exists("g:netrw_list_cmd_options")
388 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
389 else
390 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
391 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000392 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200393 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100394 if exists("g:netrw_list_cmd_options")
395 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
396 else
397 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
398 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000399 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100400" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000401 let g:netrw_list_cmd= ""
402 endif
403endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100404call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000405" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200406if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200407 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200408 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
409endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100410if !exists("g:netrw_localcmdshell")
411 let g:netrw_localcmdshell= ""
412endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000413if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200414 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000415 if g:netrw_cygwin
416 let g:netrw_localcopycmd= "cp"
417 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000418 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200419 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000420 endif
421 elseif has("unix") || has("macunix")
422 let g:netrw_localcopycmd= "cp"
423 else
424 let g:netrw_localcopycmd= ""
425 endif
426endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200428 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200430 let g:netrw_localcopydircmd = "cp"
431 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000433 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200434 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100435 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200436 elseif has("unix")
437 let g:netrw_localcopydircmd = "cp"
438 let g:netrw_localcopydircmdopt= " -R"
439 elseif has("macunix")
440 let g:netrw_localcopydircmd = "cp"
441 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100442 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200443 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100444 endif
445endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200446if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100447 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200448 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
449endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200450if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200451 if g:netrw_cygwin
452 call s:NetrwInit("g:netrw_localmkdir","mkdir")
453 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000454 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200455 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200456 endif
457else
458 call s:NetrwInit("g:netrw_localmkdir","mkdir")
459endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200460call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200461if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200462 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200463 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
464endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000465if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200466 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000467 if g:netrw_cygwin
468 let g:netrw_localmovecmd= "mv"
469 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000470 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200471 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000472 endif
473 elseif has("unix") || has("macunix")
474 let g:netrw_localmovecmd= "mv"
475 else
476 let g:netrw_localmovecmd= ""
477 endif
478endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100479" following serves as an example for how to insert a version&patch specific test
480"if v:version < 704 || (v:version == 704 && !has("patch1107"))
481"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
483" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000484if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000485 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000486endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000487if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000488 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
489endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000490" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100491call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
492call s:NetrwInit("g:netrw_maxfilenamelen", 32)
493call s:NetrwInit("g:netrw_menu" , 1)
494call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200495call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100496call s:NetrwInit("g:netrw_retmap" , 0)
497if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
498 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200499elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100500 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
501else
502 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000503endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100504call s:NetrwInit("g:netrw_preview" , 0)
505call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100506call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507call s:NetrwInit("g:netrw_sshport" , "-p")
508call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
509call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
510call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100511call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
512" Default values - q-s ---------- {{{3
513call s:NetrwInit("g:netrw_quickhelp",0)
514let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100515 \ "(create new) %:file d:directory",
516 \ "(windows split&open) o:horz v:vert p:preview",
517 \ "i:style qf:file info O:obtain r:reverse",
518 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
519 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
520 \ "(history) qb:list u:go up U:go down",
521 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100522" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
523call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100524if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
525 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
526else
527 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
528endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
530call s:NetrwInit("g:netrw_sort_options" , "")
531call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000532if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200534 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535 else
536 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000537 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000538endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100539call s:NetrwInit("g:netrw_special_syntax" , 0)
540call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200541call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100542call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100543call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000544" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200546if !exists("g:netrw_xstrlen")
547 if exists("g:Align_xstrlen")
548 let g:netrw_xstrlen= g:Align_xstrlen
549 elseif exists("g:drawit_xstrlen")
550 let g:netrw_xstrlen= g:drawit_xstrlen
551 elseif &enc == "latin1" || !has("multi_byte")
552 let g:netrw_xstrlen= 0
553 else
554 let g:netrw_xstrlen= 1
555 endif
556endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100557call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200558call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100559call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200560if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000561" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000562" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100563call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200564if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200565 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200566else
Bram Moolenaarff034192013-04-24 18:51:19 +0200567 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200568endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200569call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100570call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
571call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100572if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100573 let s:treedepthstring= "│ "
574else
575 let s:treedepthstring= "| "
576endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200577call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000578
579" BufEnter event ignored by decho when following variable is true
580" Has a side effect that doau BufReadPost doesn't work, so
581" files read by network transfer aren't appropriately highlighted.
582"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583
Bram Moolenaaradc21822011-04-01 18:03:16 +0200584" ======================
585" Netrw Initialization: {{{1
586" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200587if 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 +0100588" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100589 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200590" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100591 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100592 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
593 au VimEnter * let s:initbeval= &beval
594"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100595" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
596" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
597" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
598" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
599" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
600" 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 +0200601endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200602au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200603
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200604if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100605 com! -nargs=* NetrwKeepj keepj <args>
606else
607 let g:netrw_keepj= ""
608 com! -nargs=* NetrwKeepj <args>
609endif
610
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000611" ==============================
612" Netrw Utility Functions: {{{1
613" ==============================
614
Bram Moolenaaradc21822011-04-01 18:03:16 +0200615" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100616" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100617if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100618" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100619 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100620 if &ft != "netrw"
621 return ""
622 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200623 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
624 " popup error window is still showing
625 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
626 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
627 " text under mouse hasn't changed; only close window when it changes
628 call popup_close(s:popuperr_id)
629 unlet s:popuperr_text
630 else
631 let s:popuperr_text= v:beval_text
632 endif
633 let mesg= ""
634 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 +0100635 let mesg= ""
636 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
637 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
638 elseif getline(v:beval_lnum) =~ '^"\s*/'
639 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
640 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100641 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100642 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
643 let mesg = "S: edit sorting sequence"
644 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
645 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
646 elseif v:beval_text == "Quick" || v:beval_text == "Help"
647 let mesg = "Help: press <F1>"
648 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
649 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
650 else
651 let mesg= ""
652 endif
653 return mesg
654 endfun
655"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100656" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
657" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
658" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
659" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
660" 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 +0200661endif
662
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200664" netrw#Explore: launch the local browser in the directory of the current file {{{2
665" indx: == -1: Nexplore
666" == -2: Pexplore
667" == +: this is overloaded:
668" * If Nexplore/Pexplore is in use, then this refers to the
669" indx'th item in the w:netrw_explore_list[] of items which
670" matched the */pattern **/pattern *//pattern **//pattern
671" * If Hexplore or Vexplore, then this will override
672" g:netrw_winsize to specify the qty of rows or columns the
673" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100674" 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 +0200675" dosplit==1: the window will be split before running the local browser
676" style == 0: Explore style == 1: Explore!
677" == 2: Hexplore style == 3: Hexplore!
678" == 4: Vexplore style == 5: Vexplore!
679" == 6: Texplore
680fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100681" 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 +0100682" 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 +0200683 if !exists("b:netrw_curdir")
684 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100685" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200686 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100687
688 " record current file for Rexplore's benefit
689 if &ft != "netrw"
690 let w:netrw_rexfile= expand("%:p")
691 endif
692
693 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200694 let curdir = simplify(b:netrw_curdir)
695 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200696 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200697 let curdir= substitute(curdir,'\','/','g')
698 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100699" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100700
701 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
702 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
703 " try Explore again.
704 if a:0 > 0
705" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100706 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
707 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
708 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
709 \ '~'.expand("<slnum>"))
710 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200711 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
712 if a1 != a:1
713 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
714 return
715 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100716 endif
717 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200718
719 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200720 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100721" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100722 sil! let keepregstar = @*
723 sil! let keepregplus = @+
724 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 sil! let keepregslash= @/
726
Bram Moolenaar8d043172014-01-23 14:24:41 +0100727 " if dosplit
728 " -or- file has been modified AND file not hidden when abandoned
729 " -or- Texplore used
730 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200731 call s:SaveWinVars()
732 let winsz= g:netrw_winsize
733 if a:indx > 0
734 let winsz= a:indx
735 endif
736
737 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200738 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200739 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200740 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200741
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200742 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200745 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
747 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200750 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200754 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200755 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200756
757 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200760 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200761
762 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200764 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200765 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 6 " Texplore
768 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 exe "keepalt tabnew ".fnameescape(curdir)
770 call s:RestoreBufVars()
771 endif
772 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100774 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200775
776 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
785 if dirname !~ '/$'
786 let dirname= dirname."/"
787 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200793 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let dirname= a:1
800 endif
801 else
802 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 call s:NetrwClearExplore()
805" call Dret("netrw#Explore : cleared list")
806 return
807 endif
808
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100809" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 if dirname =~ '\.\./\=$'
811 let dirname= simplify(fnamemodify(dirname,':p:h'))
812 elseif dirname =~ '\.\.' || dirname == '.'
813 let dirname= simplify(fnamemodify(dirname,':p'))
814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100815" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200816
817 if dirname =~ '^\*//'
818 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
821 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
824
825 elseif dirname =~ '^\*\*//'
826 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 let pattern= substitute(dirname,'^\*\*//','','')
829 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831
832 elseif dirname =~ '/\*\*/'
833 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200836 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 let b:netrw_curdir = prefixdir
838 else
839 let b:netrw_curdir= getcwd().'/'.prefixdir
840 endif
841 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
842 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100843" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
844" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200845
846 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200847 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200848 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100849" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850
851 elseif dirname=~ '^\*\*/'
852 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
853 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855
856 else
857 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859 endif
860
861 if starpat == 0 && a:indx >= 0
862 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" 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 +0200864 if dirname == ""
865 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100866" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200867 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200868 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200869 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200871 if dirname == ""
872 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200873 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100874 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100875 " depending on whether backslashes have been converted to forward slashes by earlier code).
876 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200877 let dirname= b:netrw_curdir."/".dirname
878 endif
879 elseif dirname !~ '^/'
880 let dirname= b:netrw_curdir."/".dirname
881 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100882" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200883 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
885" 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 +0200886 endif
887 if exists("w:netrw_bannercnt")
888 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
889 " If one wants to return the same place in the netrw window, use :Rex instead.
890 exe w:netrw_bannercnt
891 endif
892
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100893" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200894 " ---------------------------------------------------------------------
895 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
896" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100897" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200898" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100899" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200900" endif
901 " ---------------------------------------------------------------------
902
903 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
904 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
905 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
906 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
907 elseif a:indx <= 0
908 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100909" 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 +0200910 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100911" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200912 let s:didstarstar= 1
913 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
914 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
915 endif
916
917 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 if !exists("w:netrw_explore_indx")
920 let w:netrw_explore_indx= 0
921 endif
922
923 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100924" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200925
926 if indx == -1
927 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100930 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 +0200931 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100932" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100933 if @* != keepregstar | sil! let @* = keepregstar | endif
934 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100935 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 sil! let @/ = keepregslash
937" call Dret("netrw#Explore")
938 return
939 endif
940 let indx= w:netrw_explore_indx
941 if indx < 0 | let indx= 0 | endif
942 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
943 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100944" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
946 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100947" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 endwhile
949 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100950" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200951
952 elseif indx == -2
953 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100956 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 +0200957 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100958" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100959 if @* != keepregstar | sil! let @* = keepregstar | endif
960 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100961 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 sil! let @/ = keepregslash
963" call Dret("netrw#Explore")
964 return
965 endif
966 let indx= w:netrw_explore_indx
967 if indx < 0 | let indx= 0 | endif
968 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
969 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100970" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 while indx >= 0 && curfile == w:netrw_explore_list[indx]
972 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100973" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 endwhile
975 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100976" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200977
978 else
979 " Explore -- initialize
980 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100982 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 let w:netrw_explore_indx= 0
984 if !exists("b:netrw_curdir")
985 let b:netrw_curdir= getcwd()
986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100987" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200988
989 " switch on starpat to build the w:netrw_explore_list of files
990 if starpat == 1
991 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100992" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
993" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200994 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100995 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 catch /^Vim\%((\a\+)\)\=:E480/
997 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
998" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
999 return
1000 endtry
1001 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1002 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1003
1004 elseif starpat == 2
1005 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001006" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1007" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001009 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 catch /^Vim\%((\a\+)\)\=:E480/
1011 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1012 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001013 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001014" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001015 if @* != keepregstar | sil! let @* = keepregstar | endif
1016 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001017 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 sil! let @/ = keepregslash
1019" call Dret("netrw#Explore : no files matched pattern")
1020 return
1021 endtry
1022 let s:netrw_curdir = b:netrw_curdir
1023 let w:netrw_explore_list = getqflist()
1024 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1025 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1026
1027 elseif starpat == 3
1028 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001029" 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 +02001030 let filepat= substitute(dirname,'^\*/','','')
1031 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001032" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1033" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1035 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1036
1037 elseif starpat == 4
1038 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" 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 +02001040 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1041 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1042 endif " switch on starpat to build w:netrw_explore_list
1043
1044 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001045" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1046" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001047
1048 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001049 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001050 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001051" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001052 if @* != keepregstar | sil! let @* = keepregstar | endif
1053 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001054 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001055 sil! let @/ = keepregslash
1056" call Dret("netrw#Explore : no files matched")
1057 return
1058 endif
1059 endif " if indx ... endif
1060
1061 " NetrwStatusLine support - for exploring support
1062 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001063" 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 +02001064
1065 " wrap the indx around, but issue a note
1066 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001068 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1069 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001070 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 endif
1072
1073 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 call netrw#LocalBrowseCheck(newdir)
1080 if !exists("w:netrw_liststyle")
1081 let w:netrw_liststyle= g:netrw_liststyle
1082 endif
1083 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001084 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001086 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 endif
1088 let w:netrw_explore_mtchcnt = indx + 1
1089 let w:netrw_explore_bufnr = bufnr("%")
1090 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001092" 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 +02001093
1094 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001095" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001096 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097 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 +02001098 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001099 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001100" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001101 if @* != keepregstar | sil! let @* = keepregstar | endif
1102 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001103 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001104 sil! let @/ = keepregslash
1105" call Dret("netrw#Explore : missing +path_extra")
1106 return
1107 endif
1108
1109 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001110" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1112 sil! unlet w:netrw_treedict
1113 sil! unlet w:netrw_treetop
1114 endif
1115 let newdir= dirname
1116 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001117 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001119 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 endif
1121 endif
1122
1123 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001124" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1125" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001127" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001129 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001130" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 let s:explore_prvdir = b:netrw_curdir
1132 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001133 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001134 if b:netrw_curdir !~ '/$'
1135 let dirlen= dirlen + 1
1136 endif
1137 let prvfname= ""
1138 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001139" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001140 if fname =~ '^'.b:netrw_curdir
1141 if s:explore_match == ""
1142 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1143 else
1144 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1145 endif
1146 elseif fname !~ '^/' && fname != prvfname
1147 if s:explore_match == ""
1148 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1149 else
1150 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1151 endif
1152 endif
1153 let prvfname= fname
1154 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001155" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001156 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1157 exe "2match netrwMarkFile /".s:explore_match."/"
1158 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001159 endif
1160 echo "<s-up>==Pexplore <s-down>==Nexplore"
1161 else
1162 2match none
1163 if exists("s:explore_match") | unlet s:explore_match | endif
1164 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001165" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001166 endif
1167
Bram Moolenaara6878372014-03-22 21:02:50 +01001168 " since Explore may be used to initialize netrw's browser,
1169 " there's no danger of a late FocusGained event on initialization.
1170 " Consequently, set s:netrw_events to 2.
1171 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001172 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001173" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001174 if @* != keepregstar | sil! let @* = keepregstar | endif
1175 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001176 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001177 sil! let @/ = keepregslash
1178" call Dret("netrw#Explore : @/<".@/.">")
1179endfun
1180
1181" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001182" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001183" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1184" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1185" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1186" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1187" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001189" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190 let curwin= winnr()
1191
Bram Moolenaara6878372014-03-22 21:02:50 +01001192 if a:0 > 0 && a:1 != ""
1193 " if a netrw window is already on the left-side of the tab
1194 " and a directory has been specified, explore with that
1195 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001196" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001198" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001199 exe "1wincmd w"
1200 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001201" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 exe "Explore ".fnameescape(a1)
1203 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001204 let s:lexplore_win= curwin
1205 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001207" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 unlet t:netrw_lexposn
1209 endif
1210" call Dret("netrw#Lexplore")
1211 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001212 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 exe curwin."wincmd w"
1214 else
1215 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001216" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001217 endif
1218
Bram Moolenaar8d043172014-01-23 14:24:41 +01001219 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001221 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001222" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 else
1224 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228
1229 if lexwinnr > 0
1230 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232 exe lexwinnr."wincmd w"
1233 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001234 let t:netrw_lexposn = winsaveview()
1235" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001236" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001237 close
1238 if lexwinnr < curwin
1239 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001240 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001241 if lexwinnr != curwin
1242 exe curwin."wincmd w"
1243 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246
1247 else
1248 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001249" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250 exe "1wincmd w"
1251 let keep_altv = g:netrw_altv
1252 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001253 if a:count != 0
1254 let netrw_winsize = g:netrw_winsize
1255 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001256 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001258" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 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 +02001260" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001262" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001263 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265 elseif curfile =~ '^\a\{3,}://'
1266" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 endif
1272 if a:count != 0
1273 let g:netrw_winsize = netrw_winsize
1274 endif
1275 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001276 let g:netrw_altv = keep_altv
1277 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001278 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1279 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001280 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001281 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001282" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1283" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001284 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001285" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001286" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1287 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288 unlet t:netrw_lexposn
1289 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001290 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291
1292 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001293 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001294 if a:rightside
1295 let g:netrw_chgwin= 1
1296 else
1297 let g:netrw_chgwin= 2
1298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001299" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001300 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001301
Bram Moolenaar8d043172014-01-23 14:24:41 +01001302" call Dret("netrw#Lexplore")
1303endfun
1304
1305" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001306" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001307" supports :NetrwClean -- remove netrw from first directory on runtimepath
1308" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001309fun! netrw#Clean(sys)
1310" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001311
1312 if a:sys
1313 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1314 else
1315 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1316 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001317" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318 let diddel= 0
1319 let diddir= ""
1320
1321 if choice == 1
1322 for dir in split(&rtp,',')
1323 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001324" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001325 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1326 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1327 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1328 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1329 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1330 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 +00001331 let diddir= dir
1332 let diddel= diddel + 1
1333 if !a:sys|break|endif
1334 endif
1335 endfor
1336 endif
1337
1338 echohl WarningMsg
1339 if diddel == 0
1340 echomsg "netrw is either not installed or not removable"
1341 elseif diddel == 1
1342 echomsg "removed one copy of netrw from <".diddir.">"
1343 else
1344 echomsg "removed ".diddel." copies of netrw"
1345 endif
1346 echohl None
1347
Bram Moolenaara6878372014-03-22 21:02:50 +01001348" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001349endfun
1350
Bram Moolenaar5c736222010-01-06 20:54:52 +01001351" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001352" netrw#MakeTgt: make a target out of the directory name provided {{{2
1353fun! netrw#MakeTgt(dname)
1354" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1355 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001356 let svpos = winsaveview()
1357" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001358 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1359" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001360 if s:netrwmftgt_islocal
1361 let netrwmftgt= simplify(a:dname)
1362 else
1363 let netrwmftgt= a:dname
1364 endif
1365 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1366 " re-selected target, so just clear it
1367 unlet s:netrwmftgt s:netrwmftgt_islocal
1368 else
1369 let s:netrwmftgt= netrwmftgt
1370 endif
1371 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001372 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001373 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1375 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001376" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001377endfun
1378
Bram Moolenaara6878372014-03-22 21:02:50 +01001379" ---------------------------------------------------------------------
1380" netrw#Obtain: {{{2
1381" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001382" islocal=0 obtain from remote source
1383" =1 obtain from local source
1384" fname : a filename or a list of filenames
1385" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001386fun! netrw#Obtain(islocal,fname,...)
1387" 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 +02001388 " NetrwStatusLine support - for obtaining support
1389
1390 if type(a:fname) == 1
1391 let fnamelist= [ a:fname ]
1392 elseif type(a:fname) == 3
1393 let fnamelist= a:fname
1394 else
1395 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 +01001396" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 return
1398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001399" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 if a:0 > 0
1401 let tgtdir= a:1
1402 else
1403 let tgtdir= getcwd()
1404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406
1407 if exists("b:netrw_islocal") && b:netrw_islocal
1408 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1411 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001412 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001417 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001418 if v:shell_error != 0
1419 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 +01001420" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 return
1422 endif
1423 endfor
1424 else
1425 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001426" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1427 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1428" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001429 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001430 if v:shell_error != 0
1431 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 +01001432" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 return
1434 endif
1435 endif
1436 elseif !exists("b:netrw_curdir")
1437 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1438 else
1439 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1440 endif
1441
1442 else
1443 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001444" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001445 if type(a:fname) == 1
1446 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1447 endif
1448 call s:NetrwMethod(b:netrw_curdir)
1449
1450 if b:netrw_method == 4
1451 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001452" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001453 if exists("g:netrw_port") && g:netrw_port != ""
1454 let useport= " ".g:netrw_scpport." ".g:netrw_port
1455 else
1456 let useport= ""
1457 endif
1458 if b:netrw_fname =~ '/'
1459 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1460 else
1461 let path= ""
1462 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001463 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001464 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 +02001465
1466 elseif b:netrw_method == 2
1467 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001469 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001470 let tmpbufnr= bufnr("%")
1471 setl ff=unix
1472 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001474" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 endif
1476
1477 if exists("b:netrw_fname") && b:netrw_fname != ""
1478 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481
1482 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001483 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486 for fname in fnamelist
1487 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endfor
1490 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491 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 +02001492 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endif
1495 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1496 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1497 let debugkeep= &debug
1498 setl debug=msg
1499 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1500 let &debug= debugkeep
1501 endif
1502
1503 elseif b:netrw_method == 3
1504 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001505" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001506 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001507 let tmpbufnr= bufnr("%")
1508 setl ff=unix
1509
1510 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001515" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 endif
1517
1518 if exists("g:netrw_uid") && g:netrw_uid != ""
1519 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001521" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 endif
1530 endif
1531
1532 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001533 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001534" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 endif
1536
1537 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001539" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 endif
1541
1542 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546
1547 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001548 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endif
1551 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001552 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001553 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001554" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001555
1556 " perform ftp:
1557 " -i : turns off interactive prompting from ftp
1558 " -n unix : DON'T use <.netrc>, even though it exists
1559 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001560 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1561 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001562 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001563 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1564 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001565" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001566 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001567 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 endif
1569 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001570
1571 elseif b:netrw_method == 9
1572 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001573" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001574 if a:fname =~ '/'
1575 let localfile= substitute(a:fname,'^.*/','','')
1576 else
1577 let localfile= a:fname
1578 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001579 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 +02001580
Bram Moolenaarff034192013-04-24 18:51:19 +02001581 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001582 " probably a badly formed url; protocol not recognized
1583" call Dret("netrw#Obtain : unsupported method")
1584 return
1585
1586 else
1587 " protocol recognized but not supported for Obtain (yet?)
1588 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001589 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001590 endif
1591" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001592 return
1593 endif
1594
1595 " restore status line
1596 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001597 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001598 endif
1599
1600 endif
1601
1602 " cleanup
1603 if exists("tmpbufnr")
1604 if bufnr("%") != tmpbufnr
1605 exe tmpbufnr."bw!"
1606 else
1607 q!
1608 endif
1609 endif
1610
Bram Moolenaara6878372014-03-22 21:02:50 +01001611" call Dret("netrw#Obtain")
1612endfun
1613
1614" ---------------------------------------------------------------------
1615" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1616fun! netrw#Nread(mode,fname)
1617" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001618 let svpos= winsaveview()
1619" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001620 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001621" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1622 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001623
1624 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1625 if exists("w:netrw_bannercnt")
1626 " start with cursor just after the banner
1627 exe w:netrw_bannercnt
1628 endif
1629 endif
1630" call Dret("netrw#Nread")
1631endfun
1632
1633" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001634" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1635" Options get restored by s:NetrwOptionsRestore()
1636"
1637" Option handling:
1638" * save user's options (s:NetrwOptionsSave)
1639" * set netrw-safe options (s:NetrwOptionsSafe)
1640" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1641" * restore user's options (s:netrwOPtionsRestore)
1642" - restore a user option when != safe option (s:NetrwRestoreSetting)
1643" vt: (variable type) normally its either "w:" or "s:"
1644fun! s:NetrwOptionsSave(vt)
1645" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1646" 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 +02001647" 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>"))
1648" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001649
1650 if !exists("{a:vt}netrw_optionsave")
1651 let {a:vt}netrw_optionsave= 1
1652 else
1653" call Dret("s:NetrwOptionsSave : options already saved")
1654 return
1655 endif
1656" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1657
1658 " Save current settings and current directory
1659" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1660 let s:yykeep = @@
1661 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1662 let {a:vt}netrw_aikeep = &l:ai
1663 let {a:vt}netrw_awkeep = &l:aw
1664 let {a:vt}netrw_bhkeep = &l:bh
1665 let {a:vt}netrw_blkeep = &l:bl
1666 let {a:vt}netrw_btkeep = &l:bt
1667 let {a:vt}netrw_bombkeep = &l:bomb
1668 let {a:vt}netrw_cedit = &cedit
1669 let {a:vt}netrw_cikeep = &l:ci
1670 let {a:vt}netrw_cinkeep = &l:cin
1671 let {a:vt}netrw_cinokeep = &l:cino
1672 let {a:vt}netrw_comkeep = &l:com
1673 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001674 let {a:vt}netrw_cuckeep = &l:cuc
1675 let {a:vt}netrw_culkeep = &l:cul
1676" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001677 let {a:vt}netrw_diffkeep = &l:diff
1678 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1680 let {a:vt}netrw_ffkeep = &l:ff
1681 endif
1682 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1683 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001684 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001685 let {a:vt}netrw_hidkeep = &l:hidden
1686 let {a:vt}netrw_imkeep = &l:im
1687 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001688 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 let {a:vt}netrw_lskeep = &l:ls
1690 let {a:vt}netrw_makeep = &l:ma
1691 let {a:vt}netrw_magickeep = &l:magic
1692 let {a:vt}netrw_modkeep = &l:mod
1693 let {a:vt}netrw_nukeep = &l:nu
1694 let {a:vt}netrw_rnukeep = &l:rnu
1695 let {a:vt}netrw_repkeep = &l:report
1696 let {a:vt}netrw_rokeep = &l:ro
1697 let {a:vt}netrw_selkeep = &l:sel
1698 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001699 if !g:netrw_use_noswf
1700 let {a:vt}netrw_swfkeep = &l:swf
1701 endif
1702 let {a:vt}netrw_tskeep = &l:ts
1703 let {a:vt}netrw_twkeep = &l:tw " textwidth
1704 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1705 let {a:vt}netrw_wrapkeep = &l:wrap
1706 let {a:vt}netrw_writekeep = &l:write
1707
1708 " save a few selected netrw-related variables
1709" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1710 if g:netrw_keepdir
1711 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001712" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001713 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001714 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001715 sil! let {a:vt}netrw_starkeep = @*
1716 sil! let {a:vt}netrw_pluskeep = @+
1717 endif
1718 sil! let {a:vt}netrw_slashkeep= @/
1719
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001720" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001721" 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>"))
1722" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1723endfun
1724
1725" ---------------------------------------------------------------------
1726" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1727" Use s:NetrwSaveOptions() to save user settings
1728" Use s:NetrwOptionsRestore() to restore user settings
1729fun! s:NetrwOptionsSafe(islocal)
1730" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1731" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1732" 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>"))
1733 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1734 call s:NetrwSetSafeSetting("&l:ai",0)
1735 call s:NetrwSetSafeSetting("&l:aw",0)
1736 call s:NetrwSetSafeSetting("&l:bl",0)
1737 call s:NetrwSetSafeSetting("&l:bomb",0)
1738 if a:islocal
1739 call s:NetrwSetSafeSetting("&l:bt","nofile")
1740 else
1741 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1742 endif
1743 call s:NetrwSetSafeSetting("&l:ci",0)
1744 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001745 if g:netrw_fastbrowse > a:islocal
1746 call s:NetrwSetSafeSetting("&l:bh","hide")
1747 else
1748 call s:NetrwSetSafeSetting("&l:bh","delete")
1749 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001750 call s:NetrwSetSafeSetting("&l:cino","")
1751 call s:NetrwSetSafeSetting("&l:com","")
1752 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1753 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1754 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001755 if &go =~ 'a' | set go-=a | endif
1756 if &go =~ 'A' | set go-=A | endif
1757 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001758 call s:NetrwSetSafeSetting("&l:hid",0)
1759 call s:NetrwSetSafeSetting("&l:im",0)
1760 setl isk+=@ isk+=* isk+=/
1761 call s:NetrwSetSafeSetting("&l:magic",1)
1762 if g:netrw_use_noswf
1763 call s:NetrwSetSafeSetting("swf",0)
1764 endif
1765 call s:NetrwSetSafeSetting("&l:report",10000)
1766 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1767 call s:NetrwSetSafeSetting("&l:spell",0)
1768 call s:NetrwSetSafeSetting("&l:tw",0)
1769 call s:NetrwSetSafeSetting("&l:wig","")
1770 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001771
1772 " set up cuc and cul based on g:netrw_cursor and listing style
1773 " COMBAK -- cuc cul related
1774 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001775
1776 " allow the user to override safe options
1777" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1778 if &ft == "netrw"
1779" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1780 keepalt NetrwKeepj doau FileType netrw
1781 endif
1782
1783" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1784" 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>"))
1785" call Dret("s:NetrwOptionsSafe")
1786endfun
1787
1788" ---------------------------------------------------------------------
1789" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1790fun! s:NetrwOptionsRestore(vt)
1791" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001792" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001793" 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 +01001794 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001795" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001796
1797 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1798 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001799" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001800 filetype detect
1801" 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>"))
1802 else
1803 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001804 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001805" 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 +02001806" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001807 return
1808 endif
1809 unlet {a:vt}netrw_optionsave
1810
1811 if exists("+acd")
1812 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001813" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001814 let curdir = getcwd()
1815 let &l:acd = {a:vt}netrw_acdkeep
1816 unlet {a:vt}netrw_acdkeep
1817 if &l:acd
1818 call s:NetrwLcd(curdir)
1819 endif
1820 endif
1821 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001822" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1824 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1825 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1826 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1827 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001828" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001829 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1830 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1831 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1832 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1833 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001834" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001835 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1836 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1837 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1838 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1839 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001840 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1842 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1843 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001844 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001845 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1846" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1847 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1848 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1849" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1851" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1853 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001854 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001855 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1856 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1857" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1858 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1859 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1860 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1861 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1862" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001864 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1865 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1866 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001868" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001869 call s:NetrwRestoreSetting("s:yykeep","@@")
1870 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1871 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1872 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1873 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1874
Bram Moolenaara6878372014-03-22 21:02:50 +01001875 if exists("{a:vt}netrw_swfkeep")
1876 if &directory == ""
1877 " user hasn't specified a swapfile directory;
1878 " netrw will temporarily set the swapfile directory
1879 " to the current directory as returned by getcwd().
1880 let &l:directory= getcwd()
1881 sil! let &l:swf = {a:vt}netrw_swfkeep
1882 setl directory=
1883 unlet {a:vt}netrw_swfkeep
1884 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001885 if !g:netrw_use_noswf
1886 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1887 sil! let &l:swf= {a:vt}netrw_swfkeep
1888 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001889 unlet {a:vt}netrw_swfkeep
1890 endif
1891 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001892 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001893 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1894 if exists("{a:vt}netrw_dirkeep")
1895 call s:NetrwLcd(dirkeep)
1896 unlet {a:vt}netrw_dirkeep
1897 endif
1898 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001899 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001900" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001901 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1902 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001904 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001905
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001906" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1907" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1908" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1909" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1910" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001911 " Moved the filetype detect here from NetrwGetFile() because remote files
1912 " were having their filetype detect-generated settings overwritten by
1913 " NetrwOptionRestore.
1914 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001915" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1916 filetype detect
1917" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001918 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001919" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001920" 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 +02001921" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001922endfun
1923
1924" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001925" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1926" but only when the options' value and the safe setting differ
1927" Doing this means that netrw will not come up as having changed a
1928" setting last when it really didn't actually change it.
1929"
1930" Called from s:NetrwOptionsSafe
1931" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1932fun! s:NetrwSetSafeSetting(setting,safesetting)
1933" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001934
Bram Moolenaar85850f32019-07-19 22:05:51 +02001935 if a:setting =~ '^&'
1936" call Decho("fyi: a:setting starts with &")
1937 exe "let settingval= ".a:setting
1938" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001939
Bram Moolenaar85850f32019-07-19 22:05:51 +02001940 if settingval != a:safesetting
1941" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1942 if type(a:safesetting) == 0
1943 exe "let ".a:setting."=".a:safesetting
1944 elseif type(a:safesetting) == 1
1945 exe "let ".a:setting."= '".a:safesetting."'"
1946 else
1947 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1948 endif
1949 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001950 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001951
Bram Moolenaar85850f32019-07-19 22:05:51 +02001952" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001953endfun
1954
1955" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1957" but only if the setting value differs from the associated keepvar.
1958" Doing this means that netrw will not come up as having changed a
1959" setting last when it really didn't actually change it.
1960"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001961" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001962" keepvars are set up by s:NetrwOptionsSave
1963fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001964""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001965
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966 " typically called from s:NetrwOptionsRestore
1967 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1968 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001969 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970 if exists(a:keepvar)
1971 exe "let keepvarval= ".a:keepvar
1972 exe "let setting= ".a:setting
1973
1974"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1975"" call Decho("fyi: keepvarval=".keepvarval)
1976"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1977
1978 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001979"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001980 if type(a:setting) == 0
1981 exe "let ".a:setting."= ".keepvarval
1982 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001983 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984 else
1985 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1986 endif
1987 endif
1988
1989 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001990 endif
1991
Bram Moolenaar85850f32019-07-19 22:05:51 +02001992"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001993endfun
1994
1995" ---------------------------------------------------------------------
1996" NetrwStatusLine: {{{2
1997fun! NetrwStatusLine()
1998
1999" vvv NetrwStatusLine() debugging vvv
2000" let g:stlmsg=""
2001" if !exists("w:netrw_explore_bufnr")
2002" let g:stlmsg="!X<explore_bufnr>"
2003" elseif w:netrw_explore_bufnr != bufnr("%")
2004" let g:stlmsg="explore_bufnr!=".bufnr("%")
2005" endif
2006" if !exists("w:netrw_explore_line")
2007" let g:stlmsg=" !X<explore_line>"
2008" elseif w:netrw_explore_line != line(".")
2009" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2010" endif
2011" if !exists("w:netrw_explore_list")
2012" let g:stlmsg=" !X<explore_list>"
2013" endif
2014" ^^^ NetrwStatusLine() debugging ^^^
2015
2016 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")
2017 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002018 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002019 let &laststatus = s:netrw_users_ls
2020 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2021 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2022 return ""
2023 else
2024 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2025 endif
2026endfun
2027
Bram Moolenaar85850f32019-07-19 22:05:51 +02002028" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002029" Netrw Transfer Functions: {{{1
2030" ===============================
2031
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002033" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002034" mode: =0 read remote file and insert before current line
2035" =1 read remote file and insert after current line
2036" =2 replace with remote file
2037" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002038fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002039" 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 +00002040
Bram Moolenaar5c736222010-01-06 20:54:52 +01002041 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002042 call s:NetrwOptionsSave("w:")
2043 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002044 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002045 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2046 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2047 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002048" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049
Bram Moolenaar5c736222010-01-06 20:54:52 +01002050 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 elseif a:mode == 2 " replace with remote file
2056 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002057 elseif a:mode == 3 " skip read of file (leave as temporary)
2058 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 else
2060 exe a:mode
2061 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002062 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002064" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065
Bram Moolenaar5c736222010-01-06 20:54:52 +01002066 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002067 let tmpfile= s:GetTempfile("")
2068 if tmpfile == ""
2069" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002070 return
2071 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 " attempt to repeat with previous host-file-etc
2076 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002077" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 let choice = b:netrw_lastfile
2079 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 else
2082 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002083" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002086 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002087 echomsg 'NetRead Usage:'
2088 echomsg ':Nread machine:path uses rcp'
2089 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2090 echomsg ':Nread "machine id password path" uses ftp'
2091 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2092 echomsg ':Nread fetch://machine/path uses fetch'
2093 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2094 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002095 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002096 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002097 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2098 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2099 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2100 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002101 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002102 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002103
Bram Moolenaar9964e462007-05-05 17:54:07 +00002104 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002105 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002106" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002107 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002109 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 else
2111 " case "... ... ..."
2112 let choice = strpart(choice,1,strlen(choice)-1)
2113 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002114
Bram Moolenaar9964e462007-05-05 17:54:07 +00002115 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002116 let wholechoice = wholechoice . " " . choice
2117 let ichoice = ichoice + 1
2118 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002119 if !exists("g:netrw_quiet")
2120 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2121 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 return
2124 endif
2125 let choice= a:{ichoice}
2126 endwhile
2127 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2128 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 endif
2130 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002132" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002134
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002136 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002138" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 return
2140 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002141 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002142
Bram Moolenaar8d043172014-01-23 14:24:41 +01002143 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144" 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 +02002145 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002147 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002149 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002151
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002153 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002154 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002155 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2156 echo "(netrw) Processing your read request..."
2157 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002158
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002160 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002162" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002163 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002165 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 " ER: the tmpfile is full path: rcp sees C:\... as host C
2167 if s:netrw_has_nt_rcp == 1
2168 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2169 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2170 else
2171 " Any way needed it machine contains a '.'
2172 let uid_machine = g:netrw_machine .'.'. $USERNAME
2173 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2176 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2177 else
2178 let uid_machine = g:netrw_machine
2179 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002181 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 +00002182 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002184
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002186 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002189 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002190 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002191 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002192 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002193 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002194" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002195 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002196 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002199 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202 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 +00002203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 endif
2206 " 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 +00002207 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002208 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002209 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002210 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002211 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002213 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002214 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002215 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2216 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002217 q!
2218 endif
2219 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002220 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002222
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002224 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2226 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002227" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002228 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002229 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002230 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002231 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002237" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002239
Bram Moolenaar97d62492012-11-15 21:28:22 +01002240 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002241 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002242 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002243" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002253
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002255 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002258 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002264
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 " perform ftp:
2266 " -i : turns off interactive prompting from ftp
2267 " -n unix : DON'T use <.netrc>, even though it exists
2268 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002269 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002270 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2272 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002273" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002274 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002275 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002276 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002279 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002281
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002283 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002287 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 else
2289 let useport= ""
2290 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002291 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2292 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002293 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002294 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2295 else
2296 let tmpfile_get = tmpfile
2297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002298 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 +00002299 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002300 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002301
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002303 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002304 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002305" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002307 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002309 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002310" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002311 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002312 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002313
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002314 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2315 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002317 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318 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 +00002319 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320 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 +00002321 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002322 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002323
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002325 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002326" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002327 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2328 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2330" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2331 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 +00002332 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002334 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 endif
2336 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002338 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002339
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002342 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002344
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 if !executable(g:netrw_dav_cmd)
2346 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2347" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2348 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002349 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002351 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 +01002352 else
2353 " Construct execution string (four lines) which will be passed through filter
2354 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2355 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002356 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002358 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002362 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002364 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2366 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002367
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002369 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002371 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002373 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002374 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002375
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002377 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002378 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002379" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002380 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 +00002381 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002383
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002385 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002387 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002388" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002390 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002391 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002392 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002393" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002394 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002396 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 let netrw_option= "http"
2398 else
2399 let netrw_option= "ftp"
2400 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002401" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002402
Bram Moolenaar446cb832008-06-24 21:56:24 +00002403 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002404 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 +00002405 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406 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 +00002407 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002408
Bram Moolenaar446cb832008-06-24 21:56:24 +00002409 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002412 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002415 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002416 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002417" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2418 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 +00002419 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002420 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002421
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002422 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002423 " NetRead: (file) NetRead Method #10 {{{3
2424 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002425" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2426 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002427 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2428 let b:netrw_lastfile = choice
2429
2430 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002431 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002432 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002433 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 endif
2435 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002436
Bram Moolenaar5c736222010-01-06 20:54:52 +01002437 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002439" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 unlet b:netrw_fname
2442 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002443 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 +01002444" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002445 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002447 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002448
Bram Moolenaar9964e462007-05-05 17:54:07 +00002449" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002450endfun
2451
2452" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002453" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002454fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002455" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002456
Bram Moolenaar5c736222010-01-06 20:54:52 +01002457 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002458 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002459 call s:NetrwOptionsSave("w:")
2460 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002461
Bram Moolenaar5c736222010-01-06 20:54:52 +01002462 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002463 let tmpfile= s:GetTempfile("")
2464 if tmpfile == ""
2465" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002466 return
2467 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002469 if a:0 == 0
2470 let ichoice = 0
2471 else
2472 let ichoice = 1
2473 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002474
Bram Moolenaar9964e462007-05-05 17:54:07 +00002475 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002476" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002477 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002478 " For binary writes, always write entire file.
2479 " (line numbers don't really make sense for that).
2480 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002482 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002483 elseif g:netrw_cygwin
2484 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002485 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" 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 +01002487 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002488 else
2489 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002490" 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 +01002491 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002492 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002493
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002495 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 " on the temporary file's name. Deletion of the temporary file during
2497 " cleanup then causes an error message.
2498 0file!
2499 endif
2500
Bram Moolenaar5c736222010-01-06 20:54:52 +01002501 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002503
Bram Moolenaar9964e462007-05-05 17:54:07 +00002504 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 " attempt to repeat with previous host-file-etc
2506 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002507" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 let choice = b:netrw_lastfile
2509 let ichoice= ichoice + 1
2510 else
2511 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002512
Bram Moolenaar8d043172014-01-23 14:24:41 +01002513 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002514 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002515 echomsg 'NetWrite Usage:"'
2516 echomsg ':Nwrite machine:path uses rcp'
2517 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2518 echomsg ':Nwrite "machine id password path" uses ftp'
2519 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2520 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2521 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2522 echomsg ':Nwrite rcp://machine/path uses rcp'
2523 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2524 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2525 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002526 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002527 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 elseif match(choice,"^\"") != -1
2530 if match(choice,"\"$") != -1
2531 " case "..."
2532 let choice=strpart(choice,1,strlen(choice)-2)
2533 else
2534 " case "... ... ..."
2535 let choice = strpart(choice,1,strlen(choice)-1)
2536 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002537
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002538 while match(choice,"\"$") == -1
2539 let wholechoice= wholechoice . " " . choice
2540 let ichoice = ichoice + 1
2541 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002542 if !exists("g:netrw_quiet")
2543 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2544 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002545" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002546 return
2547 endif
2548 let choice= a:{ichoice}
2549 endwhile
2550 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2551 endif
2552 endif
2553 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002555" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002556
Bram Moolenaar9964e462007-05-05 17:54:07 +00002557 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002558 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002559 if !exists("b:netrw_method") || b:netrw_method < 0
2560" call Dfunc("netrw#NetWrite : unsupported method")
2561 return
2562 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002564 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002566 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002567 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2568 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002569" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002570 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002571
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002573 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002574 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002575" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002576 if s:netrw_has_nt_rcp == 1
2577 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2578 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2579 else
2580 let uid_machine = g:netrw_machine .'.'. $USERNAME
2581 endif
2582 else
2583 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2584 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2585 else
2586 let uid_machine = g:netrw_machine
2587 endif
2588 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589 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 +00002590 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002591
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002593 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002594 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002596 let netrw_fname = b:netrw_fname
2597
2598 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2599 let bhkeep = &l:bh
2600 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002601 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002605 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002606 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002608 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002609 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002611 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002612 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615 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 +00002616 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2618 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 endif
2620 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2621 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002622 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002623 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002624 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002625 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002627
2628 " remove enew buffer (quietly)
2629 let filtbuf= bufnr("%")
2630 exe curbuf."b!"
2631 let &l:bh = bhkeep
2632 exe filtbuf."bw!"
2633
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002635
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002636 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002638 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002640" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 let netrw_fname = b:netrw_fname
2642 let bhkeep = &l:bh
2643
2644 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2645 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002646 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002648 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002651 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002654 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002657 if exists("g:netrw_uid") && g:netrw_uid != ""
2658 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002659 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002669 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002672 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002676 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " save choice/id/password for future use
2679 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002680
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002681 " perform ftp:
2682 " -i : turns off interactive prompting from ftp
2683 " -n unix : DON'T use <.netrc>, even though it exists
2684 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002685 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002686 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002687 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2688 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002689 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002690 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002691 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 let mod=1
2693 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002694
2695 " remove enew buffer (quietly)
2696 let filtbuf= bufnr("%")
2697 exe curbuf."b!"
2698 let &l:bh= bhkeep
2699 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002700
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002702 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002703 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002706 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002707 else
2708 let useport= ""
2709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002710 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 +00002711 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002712
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002714 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002716" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002717 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2718 if executable(curl)
2719 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720 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 +01002721 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002722 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002723 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002724
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002725 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002726 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002727 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002728" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002729
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002730 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002731 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2732 let bhkeep = &l:bh
2733
2734 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2735 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002736 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002738
Bram Moolenaarff034192013-04-24 18:51:19 +02002739 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002741 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002745 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002747 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002749
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002750 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002751 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002752 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002753
2754 " remove enew buffer (quietly)
2755 let filtbuf= bufnr("%")
2756 exe curbuf."b!"
2757 let &l:bh = bhkeep
2758 exe filtbuf."bw!"
2759
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002762 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002763 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002764 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002765" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002766 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 +00002767 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002768
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002769 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002771 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002772" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002773 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2775 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2776 else
2777 let uid_machine = g:netrw_machine
2778 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002779
2780 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2781 let bhkeep = &l:bh
2782 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002783 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002784 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002785
Bram Moolenaarff034192013-04-24 18:51:19 +02002786 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002789 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002790 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002791 let filtbuf= bufnr("%")
2792 exe curbuf."b!"
2793 let &l:bh = bhkeep
2794 exe filtbuf."bw!"
2795 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002796
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002797 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002799 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002800 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002801 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002803 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002804
Bram Moolenaar5c736222010-01-06 20:54:52 +01002805 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002806" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002809 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002811 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002812
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002813 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002815 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" 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 +02002817 elseif !exists("leavemod")
2818 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002820 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" 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 +00002822 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002823
Bram Moolenaar9964e462007-05-05 17:54:07 +00002824" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002825endfun
2826
2827" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002828" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829" uses NetRead to get a copy of the file into a temporarily file,
2830" then sources that file,
2831" then removes that file.
2832fun! netrw#NetSource(...)
2833" call Dfunc("netrw#NetSource() a:0=".a:0)
2834 if a:0 > 0 && a:1 == '?'
2835 " give help
2836 echomsg 'NetSource Usage:'
2837 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2838 echomsg ':Nsource fetch://machine/path uses fetch'
2839 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002840 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002841 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2842 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2843 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2844 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2845 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002846 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002848 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002853 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002855 if delete(s:netrw_tmpfile)
2856 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2857 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 unlet s:netrw_tmpfile
2859 else
2860 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2861 endif
2862 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002863 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002864 endif
2865" call Dret("netrw#NetSource")
2866endfun
2867
Bram Moolenaar8d043172014-01-23 14:24:41 +01002868" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002869" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2870" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002871fun! netrw#SetTreetop(iscmd,...)
2872" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2873" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002874
Bram Moolenaar85850f32019-07-19 22:05:51 +02002875 " iscmd==0: netrw#SetTreetop called using gn mapping
2876 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2877" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002878 " clear out the current tree
2879 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002880" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002881 let inittreetop= w:netrw_treetop
2882 unlet w:netrw_treetop
2883 endif
2884 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002886 unlet w:netrw_treedict
2887 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002888" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002889
Bram Moolenaar85850f32019-07-19 22:05:51 +02002890 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002891 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894 if isdirectory(s:NetrwFile(a:1))
2895" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002896 let treedir = a:1
2897 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = b:netrw_curdir."/".a:1
2900 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002901" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903 " normally the cursor is left in the message window.
2904 " However, here this results in the directory being listed in the message window, which is not wanted.
2905 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002908 let treedir = "."
2909 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002910 endif
2911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002913
2914 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915 let islocal= expand("%") !~ '^\a\{3,}://'
2916" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002917
2918 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002919 if islocal
2920 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2921 else
2922 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2923 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924
Bram Moolenaara6878372014-03-22 21:02:50 +01002925" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002926endfun
2927
Bram Moolenaar9964e462007-05-05 17:54:07 +00002928" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002929" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002930" readcmd == %r : replace buffer with newly read file
2931" == 0r : read file at top of buffer
2932" == r : read file after current line
2933" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002934fun! s:NetrwGetFile(readcmd, tfile, method)
2935" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002936
2937 " readcmd=='t': simply do nothing
2938 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002939" 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 +01002940" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002941 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002942 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 " get name of remote filename (ie. url and all)
2945 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 if exists("*NetReadFixup")
2949 " for the use of NetReadFixup (not otherwise used internally)
2950 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002951 endif
2952
Bram Moolenaar9964e462007-05-05 17:54:07 +00002953 if a:readcmd[0] == '%'
2954 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002955" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956
2957 " rename the current buffer to the temp file (ie. tfile)
2958 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002959 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 else
2961 let tfile= a:tfile
2962 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002963 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964
2965 " edit temporary file (ie. read the temporary file in)
2966 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 call zip#Browse(tfile)
2969 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002972 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002974 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002977 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 call tar#Browse(tfile)
2981 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002982" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002985" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002986 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002987 endif
2988
2989 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002990 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002991
Bram Moolenaar71badf92023-04-22 22:40:14 +01002992 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002993 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002994 " Note that isk must not include a "/" for scripts.vim
2995 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2997" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002998" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3000 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003001 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003002 filetype detect
3003" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003004 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003005" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003006 let line1 = 1
3007 let line2 = line("$")
3008
Bram Moolenaar8d043172014-01-23 14:24:41 +01003009 elseif !&ma
3010 " 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 +01003011 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003012" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003013 return
3014
Bram Moolenaar9964e462007-05-05 17:54:07 +00003015 elseif s:FileReadable(a:tfile)
3016 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003018 let curline = line(".")
3019 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003020" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003021 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 let line1= curline + 1
3023 let line2= line("$") - lastline + 1
3024
3025 else
3026 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3028" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003029 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003030" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003031 return
3032 endif
3033
3034 " User-provided (ie. optional) fix-it-up command
3035 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003036" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003037 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003039" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003040 endif
3041
Bram Moolenaaradc21822011-04-01 18:03:16 +02003042 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003043 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003044 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045 endif
3046
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003047" 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 +00003048
3049 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003050" redraw!
3051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" 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 +00003053" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003054endfun
3055
Bram Moolenaar9964e462007-05-05 17:54:07 +00003056" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003058" Input:
3059" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3060" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003061" b:netrw_method= 1: rcp
3062" 2: ftp + <.netrc>
3063" 3: ftp + machine, id, password, and [path]filename
3064" 4: scp
3065" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003066" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003067" 7: rsync
3068" 8: fetch
3069" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003070" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003071" g:netrw_machine= hostname
3072" b:netrw_fname = filename
3073" g:netrw_port = optional port number (for ftp)
3074" g:netrw_choice = copy of input url (choice)
3075fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003076" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003077
Bram Moolenaar251e1912011-06-19 05:09:16 +02003078 " sanity check: choice should have at least three slashes in it
3079 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3080 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3081 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003082" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003083 return
3084 endif
3085
Bram Moolenaar5c736222010-01-06 20:54:52 +01003086 " record current g:netrw_machine, if any
3087 " curmachine used if protocol == ftp and no .netrc
3088 if exists("g:netrw_machine")
3089 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003090" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003091 else
3092 let curmachine= "N O T A HOST"
3093 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003094 if exists("g:netrw_port")
3095 let netrw_port= g:netrw_port
3096 endif
3097
3098 " insure that netrw_ftp_cmd starts off every method determination
3099 " with the current g:netrw_ftp_cmd
3100 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003101
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003102 " initialization
3103 let b:netrw_method = 0
3104 let g:netrw_machine = ""
3105 let b:netrw_fname = ""
3106 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003107 let g:netrw_choice = a:choice
3108
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003110 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003111 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3112 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003113 " rcpurm : rcp://[user@]host/filename Use rcp
3114 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003116 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003117 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 " rsyncurm : rsync://host[:port]/path Use rsync
3119 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3120 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003121 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3123 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003124 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3125 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003127 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003129 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003133 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003135" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003137 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003139" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003140 let b:netrw_method = 1
3141 let userid = substitute(a:choice,rcpurm,'\1',"")
3142 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3143 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 if userid != ""
3145 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003147
Bram Moolenaaradc21822011-04-01 18:03:16 +02003148 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003150" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003151 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003152 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3153 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3154 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003155
Bram Moolenaar15146672011-10-20 22:22:38 +02003156 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003158" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003159 let b:netrw_method = 5
3160 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3161 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003162 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003163
Bram Moolenaaradc21822011-04-01 18:03:16 +02003164 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003166" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003168 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003169 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3170 else
3171 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3172 endif
3173 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003174
Bram Moolenaaradc21822011-04-01 18:03:16 +02003175 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003177" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method = 7
3179 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3180 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003185 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3187 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3188 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 if userid != ""
3191 let g:netrw_uid= userid
3192 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003193
Bram Moolenaaradc21822011-04-01 18:03:16 +02003194 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003195 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003196 call NetUserPass("ftp:".g:netrw_machine)
3197 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003198 " if there's a change in hostname, require password re-entry
3199 unlet s:netrw_passwd
3200 endif
3201 if exists("netrw_port")
3202 unlet netrw_port
3203 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003204 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003205
Bram Moolenaar446cb832008-06-24 21:56:24 +00003206 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003207 let b:netrw_method = 3
3208 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209 let host= substitute(g:netrw_machine,'\..*$','','')
3210 if exists("s:netrw_hup[host]")
3211 call NetUserPass("ftp:".host)
3212
Nir Lichtman1e34b952024-05-08 19:19:34 +02003213 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003214" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3215" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003216 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003217 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003219 endif
3220 let b:netrw_method= 2
3221 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003223 let b:netrw_method= 2
3224 else
3225 if !exists("g:netrw_uid") || g:netrw_uid == ""
3226 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003229 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 endif
3231 let b:netrw_method= 3
3232 endif
3233 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003234
Bram Moolenaaradc21822011-04-01 18:03:16 +02003235 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003237" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003238 let b:netrw_method = 8
3239 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3240 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3241 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3242 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003243
Bram Moolenaaradc21822011-04-01 18:03:16 +02003244 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003246" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3249 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003250 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003251 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003252 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003253
Bram Moolenaaradc21822011-04-01 18:03:16 +02003254 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003256" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003257 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 let b:netrw_method = 3
3259 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3260 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003261
Bram Moolenaar9964e462007-05-05 17:54:07 +00003262 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003263 let b:netrw_method = 2
3264 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3265 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3266 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003267
Bram Moolenaaradc21822011-04-01 18:03:16 +02003268 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003269 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003270" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 let b:netrw_method = 9
3272 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3273 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003274
Bram Moolenaaradc21822011-04-01 18:03:16 +02003275 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003278 let b:netrw_method = 1
3279 let userid = substitute(a:choice,rcphf,'\2',"")
3280 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3281 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003282" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3283" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3284" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3285" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003286 if userid != ""
3287 let g:netrw_uid= userid
3288 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003289
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003290 " Method#10: file://user@hostname/...path-to-file {{{3
3291 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003292" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003293 let b:netrw_method = 10
3294 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003295" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003296
Bram Moolenaaradc21822011-04-01 18:03:16 +02003297 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003298 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003299 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003300 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003301 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003302 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003304 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003305
Bram Moolenaar81695252004-12-29 20:58:21 +00003306 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003307 " remove any leading [:#] from port number
3308 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3309 elseif exists("netrw_port")
3310 " retain port number as implicit for subsequent ftp operations
3311 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003312 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003313
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003314" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3315" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3316" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3317" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003318" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003320" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003321" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003323" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003325" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327
Bram Moolenaar9964e462007-05-05 17:54:07 +00003328" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003329" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003330" Usage: :call NetUserPass() -- will prompt for userid and password
3331" :call NetUserPass("uid") -- will prompt for password
3332" :call NetUserPass("uid","password") -- sets global userid and password
3333" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3334" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335fun! NetUserPass(...)
3336
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003337" call Dfunc("NetUserPass() a:0=".a:0)
3338
3339 if !exists('s:netrw_hup')
3340 let s:netrw_hup= {}
3341 endif
3342
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003344 " case: no input arguments
3345
3346 " change host and username if not previously entered; get new password
3347 if !exists("g:netrw_machine")
3348 let g:netrw_machine= input('Enter hostname: ')
3349 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003351 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 let g:netrw_uid= input('Enter username: ')
3353 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003354 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003355 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003356
3357 " set up hup database
3358 let host = substitute(g:netrw_machine,'\..*$','','')
3359 if !exists('s:netrw_hup[host]')
3360 let s:netrw_hup[host]= {}
3361 endif
3362 let s:netrw_hup[host].uid = g:netrw_uid
3363 let s:netrw_hup[host].passwd = s:netrw_passwd
3364
3365 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003366 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367
3368 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003369 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003371" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003372 let host = substitute(a:1,'^ftp:','','')
3373 let host = substitute(host,'\..*','','')
3374 if exists("s:netrw_hup[host]")
3375 let g:netrw_uid = s:netrw_hup[host].uid
3376 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003377" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3378" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003379 else
3380 let g:netrw_uid = input("Enter UserId: ")
3381 let s:netrw_passwd = inputsecret("Enter Password: ")
3382 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003383
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003384 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003385 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003386" 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 +02003387 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003388 if g:netrw_machine =~ '[0-9.]\+'
3389 let host= g:netrw_machine
3390 else
3391 let host= substitute(g:netrw_machine,'\..*$','','')
3392 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003393 else
3394 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003395 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003396 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003397" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003398 if exists("g:netrw_passwd")
3399 " ask for password if one not previously entered
3400 let s:netrw_passwd= g:netrw_passwd
3401 else
3402 let s:netrw_passwd = inputsecret("Enter Password: ")
3403 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003404 endif
3405
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003406" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003407 if exists("host")
3408 if !exists('s:netrw_hup[host]')
3409 let s:netrw_hup[host]= {}
3410 endif
3411 let s:netrw_hup[host].uid = g:netrw_uid
3412 let s:netrw_hup[host].passwd = s:netrw_passwd
3413 endif
3414
3415 elseif a:0 == 2
3416 let g:netrw_uid = a:1
3417 let s:netrw_passwd = a:2
3418
3419 elseif a:0 == 3
3420 " enter hostname, user-id, and password into the hup dictionary
3421 let host = substitute(a:1,'^\a\+:','','')
3422 let host = substitute(host,'\..*$','','')
3423 if !exists('s:netrw_hup[host]')
3424 let s:netrw_hup[host]= {}
3425 endif
3426 let s:netrw_hup[host].uid = a:2
3427 let s:netrw_hup[host].passwd = a:3
3428 let g:netrw_uid = s:netrw_hup[host].uid
3429 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003430" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3431" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003433
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003434" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436
Bram Moolenaar85850f32019-07-19 22:05:51 +02003437" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003438" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003439" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003441" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003442" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3443fun! s:ExplorePatHls(pattern)
3444" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3445 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003449 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3450" call Dret("s:ExplorePatHls repat<".repat.">")
3451 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003452endfun
3453
3454" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003455" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003456" 0: (user: <mb>) bookmark current directory
3457" 1: (user: <gb>) change to the bookmarked directory
3458" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003459" 3: (browsing) records current directory history
3460" 4: (user: <u>) go up (previous) directory, using history
3461" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003462" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003463fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003464" 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 +02003465 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3466" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3467 return
3468 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003469
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003470 let ykeep = @@
3471 let curbufnr = bufnr("%")
3472
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473 if a:chg == 0
3474 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003475" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003476 if exists("s:netrwmarkfilelist_{curbufnr}")
3477 call s:NetrwBookmark(0)
3478 echo "bookmarked marked files"
3479 else
3480 call s:MakeBookmark(a:curdir)
3481 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003482 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003483
KSR-Yasudaf4498252023-10-06 03:34:17 +09003484 try
3485 call s:NetrwBookHistSave()
3486 catch
3487 endtry
3488
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489 elseif a:chg == 1
3490 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003491" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003492 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003494 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003495 else
3496 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3497 endif
3498
3499 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003500" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003501 let didwork= 0
3502 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003506 let cnt= 1
3507 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003508" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003509 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003510 let didwork = 1
3511 let cnt = cnt + 1
3512 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 endif
3514
3515 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003516 " Note: history is saved only when PerformListing is done;
3517 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3518 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003519 let first = 1
3520 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003522 while ( first || cnt != g:netrw_dirhistcnt )
3523" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003524 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003525" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003526 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003527 let didwork= 1
3528 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003529 let histcnt = histcnt + 1
3530 let first = 0
3531 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003532 if cnt < 0
3533 let cnt= cnt + g:netrw_dirhistmax
3534 endif
3535 endwhile
3536 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003537 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003538 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003539 if didwork
3540 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3541 endif
3542
3543 elseif a:chg == 3
3544 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003545" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546 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 +02003547 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003548 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3549 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003550 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003552 endif
3553
3554 elseif a:chg == 4
3555 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003556" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3559 if g:netrw_dirhistcnt < 0
3560 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 endif
3562 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003564 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3566" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003567 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003568 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003569" call Decho("setl ma noro",'~'.expand("<slnum>"))
3570 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003571 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003572" call Decho("setl nomod",'~'.expand("<slnum>"))
3573" 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 +00003574 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3576 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003577 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003581 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003582 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003583 echo "Sorry, no predecessor directory exists yet"
3584 endif
3585
3586 elseif a:chg == 5
3587 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003588" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003589 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003590 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3591 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3592" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003594" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003595 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003596 sil! NetrwKeepj %d _
3597" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3598" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003599 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003600" 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 +02003601 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3603 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003604 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3606 if g:netrw_dirhistcnt < 0
3607 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 endif
3609 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003610 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003612 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003613 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003615
3616 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003617" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003618 if exists("s:netrwmarkfilelist_{curbufnr}")
3619 call s:NetrwBookmark(1)
3620 echo "removed marked files from bookmarks"
3621 else
3622 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003623 let iremove = v:count
3624 let dremove = g:netrw_bookmarklist[iremove - 1]
3625" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003626 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3628 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3629 echo "removed ".dremove." from g:netrw_bookmarklist"
3630" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003632" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003633
3634 try
3635 call s:NetrwBookHistSave()
3636 catch
3637 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003638 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003639 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003640 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003641 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003642" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003643endfun
3644
3645" ---------------------------------------------------------------------
3646" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003647" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003648" Sister function: s:NetrwBookHistSave()
3649fun! s:NetrwBookHistRead()
3650" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003651 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003652" 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 +02003653 return
3654 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003655 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656
3657 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003658 if !exists("s:netrw_initbookhist")
3659 let home = s:NetrwHome()
3660 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003661 if filereadable(s:NetrwFile(savefile))
3662" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003663 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003664 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003665
3666 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003667 if g:netrw_dirhistmax > 0
3668 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003669 if filereadable(s:NetrwFile(savefile))
3670" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003671 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003672 endif
3673 let s:netrw_initbookhist= 1
3674 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677
Bram Moolenaar97d62492012-11-15 21:28:22 +01003678 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003679" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3680" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003681" call Dret("s:NetrwBookHistRead")
3682endfun
3683
3684" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003685" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686" Sister function: s:NetrwBookHistRead()
3687" I used to do this via viminfo but that appears to
3688" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003689" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3690" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003694 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003696 return
3697 endif
3698
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003702
3703 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003706 if g:netrw_use_noswf
3707 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3708 else
3709 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3710 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003711 setl nocin noai noci magic nospell nohid wig= noaw
3712 setl ma noro write
3713 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003714 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716 " rename enew'd file: .netrwhist -- no attempt to merge
3717 " record dirhistmax and current dirhistcnt
3718 " save history
3719" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003720 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003721 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003722 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3723 if g:netrw_dirhistmax > 0
3724 let lastline = line("$")
3725 let cnt = g:netrw_dirhistcnt
3726 let first = 1
3727 while ( first || cnt != g:netrw_dirhistcnt )
3728 let lastline= lastline + 1
3729 if exists("g:netrw_dirhist_{cnt}")
3730 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3731" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3732 endif
3733 let first = 0
3734 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3735 if cnt < 0
3736 let cnt= cnt + g:netrw_dirhistmax
3737 endif
3738 endwhile
3739 exe "sil! w! ".savefile
3740" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3741 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003744 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003745 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003746" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 " merge and write .netrwbook
3748 let savefile= s:NetrwHome()."/.netrwbook"
3749
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003750 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003752 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003753 for bdm in booklist
3754 if index(g:netrw_bookmarklist,bdm) == -1
3755 call add(g:netrw_bookmarklist,bdm)
3756 endif
3757 endfor
3758 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 endif
3760
3761 " construct and save .netrwbook
3762 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003763 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003764" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003766
3767 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003768 let bgone= bufnr("%")
3769 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003770 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003771
3772" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003773endfun
3774
3775" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3777" list of the contents of a local or remote directory. It is assumed that the
3778" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3779" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003780" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781fun! s:NetrwBrowse(islocal,dirname)
3782 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003783" 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 +02003784" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3785" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3786" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003787
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003788 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3789 " This is useful when one edits a local file, then :e ., then :Rex
3790 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3791 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003792" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003794
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 " s:NetrwBrowse : initialize history {{{3
3796 if !exists("s:netrw_initbookhist")
3797 NetrwKeepj call s:NetrwBookHistRead()
3798 endif
3799
3800 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003801 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003803" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003804 else
3805 let dirname= a:dirname
3806 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003807
Bram Moolenaar85850f32019-07-19 22:05:51 +02003808 " repoint t:netrw_lexbufnr if appropriate
3809 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3810" call Decho("set repointlexbufnr to true!")
3811 let repointlexbufnr= 1
3812 endif
3813
3814 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815 if exists("s:netrw_skipbrowse")
3816 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003817" 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 +01003818" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819 return
3820 endif
3821 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823" call Dret("s:NetrwBrowse : missing shellescape()")
3824 return
3825 endif
3826 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003828" call Dret("s:NetrwBrowse : missing fnameescape()")
3829 return
3830 endif
3831
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003833 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003834
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003836 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3837 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3838" call Decho("clearing marked files",'~'.expand("<slnum>"))
3839 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3840 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841 endif
3842
3843 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003844 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003845" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3846" 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 +02003847 if s:NetrwLcd(dirname)
3848" call Dret("s:NetrwBrowse : lcd failure")
3849 return
3850 endif
3851 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853
Bram Moolenaar5c736222010-01-06 20:54:52 +01003854 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003858" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003860 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003862" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863
3864 " remove any filetype indicator from end of dirname, except for the
3865 " "this is a directory" indicator (/).
3866 " There shouldn't be one of those here, anyway.
3867 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003868" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 call s:RemotePathAnalysis(dirname)
3870
3871 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3872 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003875" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 let b:netrw_curdir = dirname
3877 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003878 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3880 sil call netrw#NetRead(2,url)
3881 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("url<".url.">",'~'.expand("<slnum>"))
3883" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3884" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003885 if s:path =~ '.bz2'
3886 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3887 elseif s:path =~ '.gz'
3888 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3889 elseif s:path =~ '.gz'
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3891 else
3892 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3893 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894 endif
3895
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003896 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003897 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003898 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901" 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 +00003902
Bram Moolenaar446cb832008-06-24 21:56:24 +00003903" call Dret("s:NetrwBrowse : file<".s:fname.">")
3904 return
3905 endif
3906
Bram Moolenaaradc21822011-04-01 18:03:16 +02003907 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003908 call s:UseBufWinVars()
3909
3910 " set up some variables {{{3
3911 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003912 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913 let s:last_sort_by = g:netrw_sort_by
3914
3915 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003916 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003917
Bram Moolenaar97d62492012-11-15 21:28:22 +01003918 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003920 let svpos = winsaveview()
3921" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003923
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003925 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3926 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3927" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3928" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3929 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3930 else
3931" " call Decho("2match none",'~'.expand("<slnum>"))
3932 2match none
3933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003935 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003936 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003938 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" 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 +01003940" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003941 return
3942 endif
3943
3944 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003946 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 if b:netrw_curdir =~ '[/\\]$'
3948 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3949 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003950 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003951 let b:netrw_curdir= b:netrw_curdir."/"
3952 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 if b:netrw_curdir == ''
3954 if has("amiga")
3955 " On the Amiga, the empty string connotes the current directory
3956 let b:netrw_curdir= getcwd()
3957 else
3958 " under unix, when the root directory is encountered, the result
3959 " from the preceding substitute is an empty string.
3960 let b:netrw_curdir= '/'
3961 endif
3962 endif
3963 if !a:islocal && b:netrw_curdir !~ '/$'
3964 let b:netrw_curdir= b:netrw_curdir.'/'
3965 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003966" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003967
3968 " ------------
3969 " (local only) {{{3
3970 " ------------
3971 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003972" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003973
3974 " Set up ShellCmdPost handling. Append current buffer to browselist
3975 call s:LocalFastBrowser()
3976
3977 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3978 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3980" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003982 if s:NetrwLcd(b:netrw_curdir)
3983" call Dret("s:NetrwBrowse : lcd failure")
3984 return
3985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003986 endif
3987 endif
3988
3989 " --------------------------------
3990 " remote handling: {{{3
3991 " --------------------------------
3992 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003993" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994
Bram Moolenaar97d62492012-11-15 21:28:22 +01003995 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996" 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 +02003997 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003999" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004000 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4001 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4002 if dirname !~ '/$'
4003 let dirname= dirname.'/'
4004 endif
4005 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004008 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004009" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010 endif
4011
4012 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4013 if dirname !~ dirpat
4014 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004015 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004016 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004017 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004019 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004020" 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 +00004021" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4022 return
4023 endif
4024 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004026 endif " (additional remote handling)
4027
Bram Moolenaar85850f32019-07-19 22:05:51 +02004028 " -------------------------------
4029 " Perform Directory Listing: {{{3
4030 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004031 NetrwKeepj call s:NetrwMaps(a:islocal)
4032 NetrwKeepj call s:NetrwCommands(a:islocal)
4033 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004034
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004035 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004036 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004037" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4038
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004039 " If there is a rexposn: restore position with rexposn
4040 " Otherwise : set rexposn
4041 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4043 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4044 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4045 NetrwKeepj exe w:netrw_bannercnt
4046 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004047 else
4048 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4049 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004050 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004051 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004052" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004053 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004054 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004055
Bram Moolenaar85850f32019-07-19 22:05:51 +02004056 " repoint t:netrw_lexbufnr if appropriate
4057 if exists("repointlexbufnr")
4058 let t:netrw_lexbufnr= bufnr("%")
4059" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4060 endif
4061
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062 " restore position
4063 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004064" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4065 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004066 endif
4067
Bram Moolenaara6878372014-03-22 21:02:50 +01004068 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004069 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4070 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004071" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4072" 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 +02004073" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004074 return
4075endfun
4076
4077" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4079" may not apply correctly; ie. netrw's idea of the current directory may
4080" differ from vim's. This function insures that netrw's idea of the current
4081" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004084" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4085" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4086" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4087" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4088" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004089
4090 " clean up any leading treedepthstring
4091 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4092 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004093" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094 else
4095 let fname= a:fname
4096 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004097
4098 if g:netrw_keepdir
4099 " vim's idea of the current directory possibly may differ from netrw's
4100 if !exists("b:netrw_curdir")
4101 let b:netrw_curdir= getcwd()
4102 endif
4103
Nir Lichtman1e34b952024-05-08 19:19:34 +02004104 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004105 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004106 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004107 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004108" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109 else
4110 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004111 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004112" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 endif
4114
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119 else
4120 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004121 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004122" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 endif
4124 else
4125 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004126 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4128" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4129" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 endif
4131
Bram Moolenaar85850f32019-07-19 22:05:51 +02004132" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133 return ret
4134endfun
4135
4136" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004137" s:NetrwFileInfo: supports qf (query for file information) {{{2
4138fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004139" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004140 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004141 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004143 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004145 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let lsopt= "-lsadh --si"
4147 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004148" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004150
4151 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004152 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004154
Bram Moolenaara6878372014-03-22 21:02:50 +01004155 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004158
4159 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004162
Bram Moolenaar446cb832008-06-24 21:56:24 +00004163 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004165 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 endif
4168 else
4169 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4171 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004172 let fname= substitute(a:fname,".$","","")
4173 else
4174 let fname= a:fname
4175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176 let t = getftime(s:NetrwFile(fname))
4177 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004178 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004179 let sz= s:NetrwHumanReadable(sz)
4180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4182" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004183 endif
4184 else
4185 echo "sorry, \"qf\" not supported yet for remote files"
4186 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004187 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188" call Dret("s:NetrwFileInfo")
4189endfun
4190
4191" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004192" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4193fun! s:NetrwFullPath(filename)
4194" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4195 let filename= a:filename
4196 if filename !~ '^/'
4197 let filename= resolve(getcwd().'/'.filename)
4198 endif
4199 if filename != "/" && filename =~ '/$'
4200 let filename= substitute(filename,'/$','','')
4201 endif
4202" " call Dret("s:NetrwFullPath <".filename.">")
4203 return filename
4204endfun
4205
4206" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004207" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004209" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004210" 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 +00004211fun! s:NetrwGetBuffer(islocal,dirname)
4212" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004213" 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 +02004214" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4215" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004216 let dirname= a:dirname
4217
4218 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004219" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004220 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004221" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004222 let s:netrwbuf= {}
4223 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004224" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4225" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4226
4227 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4228 let bufnum = -1
4229
4230 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4231 if has_key(s:netrwbuf,"NetrwTreeListing")
4232 let bufnum= s:netrwbuf["NetrwTreeListing"]
4233 else
4234 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4235 endif
4236" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4237 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004238 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004239 let bufnum= -1
4240 endif
4241 elseif bufnr("NetrwTreeListing") != -1
4242 let bufnum= bufnr("NetrwTreeListing")
4243" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4244 else
4245" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4246 let bufnum= -1
4247 endif
4248
4249 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004250 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004251" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004252 if !bufexists(bufnum)
4253 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4254 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256
Bram Moolenaar446cb832008-06-24 21:56:24 +00004257 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004261" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4262
Bram Moolenaar71badf92023-04-22 22:40:14 +01004263 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004264 " IF the buffer already has the desired name
4265 " AND it is empty
4266 let curbuf = bufname("%")
4267 if curbuf == '.'
4268 let curbuf = getcwd()
4269 endif
4270" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004271" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004272" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4273" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4274" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4275" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4276 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004277" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4278 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004279 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004280" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004281 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004282 " 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 +00004283
4284 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004285 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" 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 +00004287 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004289 " name the buffer
4290 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4291 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004292" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004293 let w:netrw_treebufnr = bufnr("%")
4294 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004295 if g:netrw_use_noswf
4296 setl nobl bt=nofile noswf
4297 else
4298 setl nobl bt=nofile
4299 endif
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>
4303 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004304" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004306 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004307 " enter the new buffer into the s:netrwbuf dictionary
4308 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4309" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4310" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004312" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313
4314 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004315" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004316 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004318 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004319
4320 if &ft == "netrw"
4321" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4322 exe "sil! NetrwKeepj noswapfile b ".bufnum
4323" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004325" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4326 call s:NetrwEditBuf(bufnum)
4327" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004329" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004331 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004333
4334 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004336
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337 if line("$") <= 1 && getline(1) == ""
4338 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004339 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340" 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>"))
4341" 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 +01004342" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4343 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004344
Bram Moolenaar97d62492012-11-15 21:28:22 +01004345 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004347 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004348 sil NetrwKeepj %d _
4349" 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>"))
4350" 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 +01004351" 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 +00004352 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004353
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4356" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004357 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004358 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004359 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360" 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>"))
4361" 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 +01004362" 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 +00004363 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004364
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004366" 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>"))
4367" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4368" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 return 1
4370 endif
4371 endif
4372
4373 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4374 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4375 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4376 " med 1 D H
4377 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004378" 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 +00004379 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004380 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004381 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004382
4383 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004384" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4385" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4386 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388" 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>"))
4389" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4390" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 return 0
4392endfun
4393
4394" ---------------------------------------------------------------------
4395" s:NetrwGetcwd: get the current directory. {{{2
4396" Change backslashes to forward slashes, if any.
4397" If doesc is true, escape certain troublesome characters
4398fun! s:NetrwGetcwd(doesc)
4399" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4400 let curdir= substitute(getcwd(),'\\','/','ge')
4401 if curdir !~ '[\/]$'
4402 let curdir= curdir.'/'
4403 endif
4404 if a:doesc
4405 let curdir= fnameescape(curdir)
4406 endif
4407" call Dret("NetrwGetcwd <".curdir.">")
4408 return curdir
4409endfun
4410
4411" ---------------------------------------------------------------------
4412" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4413fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004414" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4415" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4416 let keepsol= &l:sol
4417 setl nosol
4418
Bram Moolenaar446cb832008-06-24 21:56:24 +00004419 call s:UseBufWinVars()
4420
4421 " insure that w:netrw_liststyle is set up
4422 if !exists("w:netrw_liststyle")
4423 if exists("g:netrw_liststyle")
4424 let w:netrw_liststyle= g:netrw_liststyle
4425 else
4426 let w:netrw_liststyle= s:THINLIST
4427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004428" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429 endif
4430
4431 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4432 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004433" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004434 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 let dirname= "./"
4436 let curline= getline('.')
4437
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004438 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004439 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let s:netrw_skipbrowse= 1
4441 echo 'Pressing "s" also works'
4442
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004443 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 let s:netrw_skipbrowse= 1
4445 echo 'Press "S" to edit sorting sequence'
4446
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004447 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004448 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004451 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004452 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453 let s:netrw_skipbrowse= 1
4454 echo 'Pressing "a" also works'
4455
4456 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004457 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 endif
4459
4460 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004461" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004462 NetrwKeepj norm! 0
4463 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004464
4465 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004466" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004467 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4469
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004470 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004471" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004472 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004473 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474
4475 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004476" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004477 let dirname= getline('.')
4478
4479 if !exists("b:netrw_cpf")
4480 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004481 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 +01004482 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 endif
4485
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4489" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004491 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 else
4493 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004494 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 endif
Enno3146d632024-07-04 19:44:42 +02004496
4497 let dict={}
4498 " save the unnamed register and register 0-9 and a
4499 let dict.a=[getreg('a'), getregtype('a')]
4500 for i in range(0, 9)
4501 let dict[i] = [getreg(i), getregtype(i)]
4502 endfor
4503 let dict.unnamed = [getreg(''), getregtype('')]
4504
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 let eofname= filestart + b:netrw_cpf + 1
4506 if eofname <= col("$")
4507 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004508 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004509 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004510 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004511 endif
Enno3146d632024-07-04 19:44:42 +02004512
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004514 call s:RestoreRegister(dict)
4515
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004516" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004519 endif
4520
4521 " symlinks are indicated by a trailing "@". Remove it before further processing.
4522 let dirname= substitute(dirname,"@$","","")
4523
4524 " executables are indicated by a trailing "*". Remove it before further processing.
4525 let dirname= substitute(dirname,"\*$","","")
4526
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004527 let &l:sol= keepsol
4528
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529" call Dret("s:NetrwGetWord <".dirname.">")
4530 return dirname
4531endfun
4532
4533" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004534" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4535" g:netrw_bufsettings will be used after the listing is produced.
4536" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537fun! s:NetrwListSettings(islocal)
4538" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004539" 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 +00004540 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004541" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4542 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4543 setl bt=nofile nobl ma nonu nowrap noro nornu
4544 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004548" call Dredir("ls!","s:NetrwListSettings")
4549" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004550 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004551 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004553 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004555 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004557" 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 +00004558" call Dret("s:NetrwListSettings")
4559endfun
4560
4561" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004562" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563" islocal=0: remote browsing
4564" =1: local browsing
4565fun! s:NetrwListStyle(islocal)
4566" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004567
Bram Moolenaar97d62492012-11-15 21:28:22 +01004568 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 let fname = s:NetrwGetWord()
4570 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004571 let svpos = winsaveview()
4572" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004574" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4575" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4576" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004577
Bram Moolenaar85850f32019-07-19 22:05:51 +02004578 " repoint t:netrw_lexbufnr if appropriate
4579 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4580" call Decho("set repointlexbufnr to true!")
4581 let repointlexbufnr= 1
4582 endif
4583
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 if w:netrw_liststyle == s:THINLIST
4585 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004586" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004587 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4588
4589 elseif w:netrw_liststyle == s:LONGLIST
4590 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4593
4594 elseif w:netrw_liststyle == s:WIDELIST
4595 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004596" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4598
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004599 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004600" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4602
4603 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004604 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004605 let g:netrw_liststyle = s:THINLIST
4606 let w:netrw_liststyle = g:netrw_liststyle
4607 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4608 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004609 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004611
4612 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4614 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004615 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004616" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004617 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" 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 +00004619
4620 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004621" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004622 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004623 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004624
Bram Moolenaar85850f32019-07-19 22:05:51 +02004625 " repoint t:netrw_lexbufnr if appropriate
4626 if exists("repointlexbufnr")
4627 let t:netrw_lexbufnr= bufnr("%")
4628" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4629 endif
4630
Bram Moolenaar13600302014-05-22 18:26:40 +02004631 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004632" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4633 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004634 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004635
4636" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4637endfun
4638
4639" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004640" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4641fun! s:NetrwBannerCtrl(islocal)
4642" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4643
Bram Moolenaar97d62492012-11-15 21:28:22 +01004644 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004645 " toggle the banner (enable/suppress)
4646 let g:netrw_banner= !g:netrw_banner
4647
4648 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004649 let svpos= winsaveview()
4650" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004651 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4652
4653 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004654 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4655 let fname= s:NetrwGetWord()
4656 sil NetrwKeepj $
4657 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4658" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4659 if result <= 0 && exists("w:netrw_bannercnt")
4660 exe "NetrwKeepj ".w:netrw_bannercnt
4661 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004662 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004663 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004664" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4665endfun
4666
4667" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004668" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4669"
4670" No bang: enters files/directories into Netrw's bookmark system
4671" No argument and in netrw buffer:
4672" if there are marked files: bookmark marked files
4673" otherwise : bookmark file/directory under cursor
4674" No argument and not in netrw buffer: bookmarks current open file
4675" Has arguments: globs them individually and bookmarks them
4676"
4677" With bang: deletes files/directories from Netrw's bookmark system
4678fun! s:NetrwBookmark(del,...)
4679" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4680 if a:0 == 0
4681 if &ft == "netrw"
4682 let curbufnr = bufnr("%")
4683
4684 if exists("s:netrwmarkfilelist_{curbufnr}")
4685 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004686" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004687 let svpos = winsaveview()
4688" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004689 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004690 for fname in s:netrwmarkfilelist_{curbufnr}
4691 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4692 endfor
4693 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4694 call s:NetrwUnmarkList(curbufnr,curdir)
4695 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004696" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4697 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004698 else
4699 let fname= s:NetrwGetWord()
4700 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4701 endif
4702
4703 else
4704 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004705" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004706 let fname= expand("%")
4707 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4708 endif
4709
4710 else
4711 " bookmark specified files
4712 " attempts to infer if working remote or local
4713 " by deciding if the current file begins with an url
4714 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 let islocal= expand("%") !~ '^\a\{3,}://'
4716" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004717 let i = 1
4718 while i <= a:0
4719 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004720 if v:version > 704 || (v:version == 704 && has("patch656"))
4721 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004723 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 else
4726 let mbfiles= [a:{i}]
4727 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004728" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004729 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004730" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004731 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4732 endfor
4733 let i= i + 1
4734 endwhile
4735 endif
4736
4737 " update the menu
4738 call s:NetrwBookmarkMenu()
4739
4740" call Dret("s:NetrwBookmark")
4741endfun
4742
4743" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004744" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4745" .2.[cnt] for bookmarks, and
4746" .3.[cnt] for history
4747" (see s:NetrwMenu())
4748fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004749 if !exists("s:netrw_menucnt")
4750 return
4751 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004752" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004753
4754 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004755 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004756 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004758 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4759 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004760 endif
4761 if !exists("s:netrw_initbookhist")
4762 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004763 endif
4764
4765 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004766 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004767 let cnt= 1
4768 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004769" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004770 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004771
4772 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004773 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004774
4775 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004776 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 +01004777 let cnt= cnt + 1
4778 endfor
4779
4780 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004781
4782 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004783 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004784 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 let first = 1
4786 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004787 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004789 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004790 if exists("g:netrw_dirhist_{cnt}")
4791 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004792" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004793 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4794 endif
4795 let first = 0
4796 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4797 if cnt < 0
4798 let cnt= cnt + g:netrw_dirhistmax
4799 endif
4800 endwhile
4801 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004802
Bram Moolenaar9964e462007-05-05 17:54:07 +00004803 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004805endfun
4806
4807" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004808" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4809" directory and a new directory name. Also, if the
4810" "new directory name" is actually a file,
4811" NetrwBrowseChgDir() edits the file.
4812fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004813" 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 +01004814" 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 +00004815
Bram Moolenaar97d62492012-11-15 21:28:22 +01004816 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004817 if !exists("b:netrw_curdir")
4818 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4819 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004820 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4822" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004823" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004824" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004825 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004826 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004827" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004828
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004829 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004830" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004831 call s:SavePosn(s:netrw_posn)
4832 NetrwKeepj call s:NetrwOptionsSave("s:")
4833 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004834 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004835 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004836 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004837 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004838 endif
4839 let newdir = a:newdir
4840 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004841 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004842" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004844" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004845
4846 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004847" 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 +01004848 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004849" 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 +01004850 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004851 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004852" 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 +01004853 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004854" 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 +02004855 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004856 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004857 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004858 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" 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 +01004860 endif
4861 endif
4862" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004863" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004864 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004865
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 " set up o/s-dependent directory recognition pattern
4867 if has("amiga")
4868 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004869 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 let dirpat= '[\/]$'
4871 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004872" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873
4874 if dirname !~ dirpat
4875 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004876 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004879 endif
4880
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004881" 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 +01004882 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004883 " ------------------------------
4884 " NetrwBrowseChgDir: edit a file {{{3
4885 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004886" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004887
Bram Moolenaar97d62492012-11-15 21:28:22 +01004888 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004889 let s:rexposn_{bufnr("%")}= winsaveview()
4890" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004891" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4892" 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 +01004893
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004895" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4896" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004897" let newdir = s:NetrwTreePath(s:netrw_treetop)
4898" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004899 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004900 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4901" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4902 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 if dirname =~ '/$'
4904 let dirname= dirname.newdir
4905 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004906 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004908" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4909" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004911" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004913 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004916" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004917 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004919" 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 +02004920 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004921 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004923" " 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 +01004924 if type(g:netrw_browse_split) == 3
4925 " open file in server
4926 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004927" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004928 call s:NetrwServerEdit(a:islocal,dirname)
4929" call Dret("s:NetrwBrowseChgDir")
4930 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004931
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004932 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004933 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004934" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004935 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4936 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004938 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004939 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004940 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004941
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004943 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004944" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004945 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4946 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004947 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004948 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004949 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004950 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004951
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004953 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004955 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004956 if !exists("b:netrw_curdir")
4957 let b:netrw_curdir= getcwd()
4958 endif
4959 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004960
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004962 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004963" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004964 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004965 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004967 return
4968 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004969 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004970
Bram Moolenaar9964e462007-05-05 17:54:07 +00004971 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004974 call s:NetrwMenu(0)
4975 " optional change to window
4976 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004977" 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 +02004978 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004979 " if g:netrw_chgwin is set to one more than the last window, then
4980 " vertically split the last window to make that window available.
4981 let curwin= winnr()
4982 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4983 vs
4984 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004985 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004986 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004987 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004988 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004989 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004990
Bram Moolenaar9964e462007-05-05 17:54:07 +00004991 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004992
Bram Moolenaar446cb832008-06-24 21:56:24 +00004993 " the point where netrw actually edits the (local) file
4994 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004995 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004996 if !&mod
4997 " if e the new file would fail due to &mod, then don't change any of the flags
4998 let dolockout= 1
4999 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005000 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005001" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005002 " some like c-^ to return to the last edited file
5003 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005004 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5005 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005006 call s:NetrwEditFile("e","",dirname)
5007" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005008 " COMBAK -- cuc cul related
5009 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005010 if &hidden || &bufhidden == "hide"
5011 " file came from vim's hidden storage. Don't "restore" options with it.
5012 let dorestore= 0
5013 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005014 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005015" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005016 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005017
5018 " handle g:Netrw_funcref -- call external-to-netrw functions
5019 " This code will handle g:Netrw_funcref as an individual function reference
5020 " or as a list of function references. It will ignore anything that's not
5021 " a function reference. See :help Funcref for information about function references.
5022 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005023" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005026 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005027 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005029 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005030 if type(Fncref) == 2
5031 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005032 endif
5033 endfor
5034 endif
5035 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036 endif
5037
5038 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005039 " ----------------------------------------------------
5040 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5041 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005043 let dirname = newdir
5044 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005045 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005046 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047
5048 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005049 " ---------------------------------------------
5050 " NetrwBrowseChgDir: refresh the directory list {{{3
5051 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005052" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005053 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055
5056 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005057 " --------------------------------------
5058 " NetrwBrowseChgDir: go up one directory {{{3
5059 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005060" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061
5062 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5063 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005064" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5065" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005066 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 endif
5069
5070 if has("amiga")
5071 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 if a:islocal
5074 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5075 let dirname= substitute(dirname,'/$','','')
5076 else
5077 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080
Nir Lichtman1e34b952024-05-08 19:19:34 +02005081 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005082 " windows
5083 if a:islocal
5084 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5085 if dirname == ""
5086 let dirname= '/'
5087 endif
5088 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005090 endif
5091 if dirname =~ '^\a:$'
5092 let dirname= dirname.'/'
5093 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005095
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096 else
5097 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005098" 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 +00005099 if a:islocal
5100 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5101 if dirname == ""
5102 let dirname= '/'
5103 endif
5104 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005107" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005109 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005110 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111
5112 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005113 " --------------------------------------
5114 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5115 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005116" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5118" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005119 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5122 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005125" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005126 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005127 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005128" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129
5130 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005131" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005133" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 let haskey= 1
5135 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 endif
5138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005139 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005140" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005141 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 if has_key(w:netrw_treedict,treedir."/")
5143 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 let haskey = 1
5146 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 endif
5149 endif
5150
5151 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005152" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 if !haskey && treedir =~ '/$'
5154 let treedir= substitute(treedir,'/$','','')
5155 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005156" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 let haskey = 1
5158 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 endif
5161 endif
5162
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 if haskey
5165 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5169" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005170 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 else
5172 " go down one directory
5173 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5175" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005177 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005179 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180
5181 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005182 " ----------------------------------------
5183 " NetrwBrowseChgDir: Go down one directory {{{3
5184 " ----------------------------------------
5185 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005186" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005187 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005189 endif
5190
Bram Moolenaar97d62492012-11-15 21:28:22 +01005191 " --------------------------------------
5192 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5193 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005194 if dorestore
5195 " dorestore is zero'd when a local file was hidden or bufhidden;
5196 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005198 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005199" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005202 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005204 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5206" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005207 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" 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 +02005209 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5211" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005212 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005213" 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 +02005214 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005216 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005217 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005218
Bram Moolenaar446cb832008-06-24 21:56:24 +00005219" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5220 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005221endfun
5222
5223" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005224" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5225" for thin, long, and wide: cursor placed just after banner
5226" for tree, keeps cursor on current filename
5227fun! s:NetrwBrowseUpDir(islocal)
5228" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005229 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5230 " this test needed because occasionally this function seems to be incorrectly called
5231 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005233 " directories.
5234" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5235 return
5236 endif
5237
Bram Moolenaara6878372014-03-22 21:02:50 +01005238 norm! 0
5239 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005240" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 let curline= getline(".")
5242 let swwline= winline() - 1
5243 if exists("w:netrw_treetop")
5244 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005245 elseif exists("b:netrw_curdir")
5246 let w:netrw_treetop= b:netrw_curdir
5247 else
5248 let w:netrw_treetop= getcwd()
5249 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005251 let curfile = getline(".")
5252 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005253 if a:islocal
5254 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5255 else
5256 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005258" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5259" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5260 if w:netrw_treetop == '/'
5261 keepj call search('^\M'.curfile,"w")
5262 elseif curfile == '../'
5263 keepj call search('^\M'.curfile,"wb")
5264 else
5265" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5266 while 1
5267 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5268 let treepath= s:NetrwTreePath(w:netrw_treetop)
5269" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5270 if treepath == curpath
5271 break
5272 endif
5273 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005274 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275
Bram Moolenaara6878372014-03-22 21:02:50 +01005276 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005277" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005278 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005279 if exists("b:netrw_curdir")
5280 let curdir= b:netrw_curdir
5281 else
5282 let curdir= expand(getcwd())
5283 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005284 if a:islocal
5285 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5286 else
5287 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5288 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005289 call s:RestorePosn(s:netrw_posn)
5290 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005291 let curdir= '\<'. escape(curdir, '~'). '/'
5292 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005293 endif
5294" call Dret("s:NetrwBrowseUpDir")
5295endfun
5296
5297" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005298" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005299" given filename; typically this means given their extension.
5300" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005301fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005302 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005303" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005304
Bram Moolenaar91359012019-11-30 17:57:03 +01005305 if a:remote == 0 && isdirectory(a:fname)
5306 " if its really just a local directory, then do a "gf" instead
5307" 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 +01005308" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5309 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005310" call Dret("netrw#BrowseX")
5311 return
5312 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5313 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5314" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5315" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5316" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5317" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5318 norm! gf
5319" call Dret("netrw#BrowseX")
5320 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005321 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005322" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005323
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005324 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5325 let remote = a:remote
5326 else
5327 let remote = 0
5328 endif
5329
Bram Moolenaar97d62492012-11-15 21:28:22 +01005330 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005331 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005332" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005333
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005334 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5335 let awkeep = &aw
5336 set noaw
5337
Bram Moolenaar5c736222010-01-06 20:54:52 +01005338 " special core dump handler
5339 if a:fname =~ '/core\(\.\d\+\)\=$'
5340 if exists("g:Netrw_corehandler")
5341 if type(g:Netrw_corehandler) == 2
5342 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005343" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005344 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005345 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005346 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005347" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005348 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005349 if type(Fncref) == 2
5350 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005351 endif
5352 endfor
5353 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005354" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005355 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005356 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005357 let &aw= awkeep
5358" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005359 return
5360 endif
5361 endif
5362
Bram Moolenaar446cb832008-06-24 21:56:24 +00005363 " set up the filename
5364 " (lower case the extension, make a local copy of a remote file)
5365 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005366 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005368 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005369 if exten =~ "[\\/]"
5370 let exten= ""
5371 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005372" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005373
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005374 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005375 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005376" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005377 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005378 call netrw#NetRead(3,a:fname)
5379 " attempt to rename tempfile
5380 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005381 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005382" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5383" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005384 if s:netrw_tmpfile != newname && newname != ""
5385 if rename(s:netrw_tmpfile,newname) == 0
5386 " renaming succeeded
5387" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5388 let fname= newname
5389 else
5390 " renaming failed
5391" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5392 let fname= s:netrw_tmpfile
5393 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005394 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005395 let fname= s:netrw_tmpfile
5396 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005397 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005398" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005399 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005400 " special ~ handler for local
5401 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005402" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5403 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005404 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005406" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5407" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005408
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005409 " set up redirection (avoids browser messages)
5410 " by default, g:netrw_suppress_gx_mesg is true
5411 if g:netrw_suppress_gx_mesg
5412 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005413 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005414 let redir= substitute(&srr,"%s","nul","")
5415 else
5416 let redir= substitute(&srr,"%s","/dev/null","")
5417 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005418 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005419 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005421 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005423 else
5424 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005426" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005427
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005428 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005429 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005430" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005431 if g:netrw_browsex_viewer =~ '\s'
5432 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5433 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5434 let oviewer = ''
5435 let cnt = 1
5436 while !executable(viewer) && viewer != oviewer
5437 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5438 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5439 let cnt = cnt + 1
5440 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005441" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 endwhile
5443 else
5444 let viewer = g:netrw_browsex_viewer
5445 let viewopt = ""
5446 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005447" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448 endif
5449
5450 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005451" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Luca Saccarolaa7d45612024-10-21 21:27:03 +02005452 if exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005453" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005454 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005455 let ret= v:shell_error
5456
Nir Lichtman1e34b952024-05-08 19:19:34 +02005457 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005458" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005459 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005460 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005461 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005462 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005463 else
5464 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5465 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005466 let ret= v:shell_error
5467
Bram Moolenaar97d62492012-11-15 21:28:22 +01005468 elseif has("win32unix")
5469 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005471 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005472" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005473 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005474 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005475" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005476 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005477 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005478" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005479 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005480 else
5481 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5482 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005483 let ret= v:shell_error
5484
Bram Moolenaar85850f32019-07-19 22:05:51 +02005485 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005486" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5487 if a:fname =~ '^https\=://'
5488 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5489 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005490" call Decho("fname<".fname.">")
5491" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005492 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5493
5494 else
5495 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5496 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005497 let ret= v:shell_error
5498
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005499 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5500" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5501 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5502 let ret= v:shell_error
5503
5504 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5505" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5506 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5507 let ret= v:shell_error
5508
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005509 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005510" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005511 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005512 let ret= v:shell_error
5513
5514 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005515" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005516 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005517 let ret= v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00005518 else
Luca Saccarolaa7d45612024-10-21 21:27:03 +02005519 call netrw#ErrorMsg(s:ERROR, "Couldn't find a program to open '".a:fname."'", 0)
5520 let ret=0
Bram Moolenaar446cb832008-06-24 21:56:24 +00005521 endif
5522
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 if ret
Luca Saccarolaa7d45612024-10-21 21:27:03 +02005524 call netrw#ErrorMsg(s:ERROR, "Failed to open '".a:fname."'", 0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 endif
5526
Bram Moolenaarc236c162008-07-13 17:41:49 +00005527 " restoring redraw! after external file handlers
5528 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005529
5530 " cleanup: remove temporary file,
5531 " delete current buffer if success with handler,
5532 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005533 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005534 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005535" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005536"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005537" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005538" endif
5539
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005540 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005541 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005543 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005545 if use_ctrlo
5546 exe "sil! NetrwKeepj norm! \<c-o>"
5547 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005549" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005550 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005551 let @@ = ykeep
5552 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005554" call Dret("netrw#BrowseX")
5555endfun
5556
5557" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005558" netrw#GX: gets word under cursor for gx support {{{2
5559" See also: netrw#BrowseXVis
5560" netrw#BrowseX
5561fun! netrw#GX()
5562" call Dfunc("netrw#GX()")
5563 if &ft == "netrw"
5564 let fname= s:NetrwGetWord()
5565 else
5566 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5567 endif
5568" call Dret("netrw#GX <".fname.">")
5569 return fname
5570endfun
5571
5572" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005573" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5574fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005575 let dict={}
5576 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005577 norm! gv"ay
5578 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005579 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005580 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005581endfun
5582
5583" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005584" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5585" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5586" to become an unlisted buffer, so in that case don't bwipe it.
5587fun! s:NetrwBufRename(newname)
5588" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5589" call Dredir("ls!","s:NetrwBufRename (before rename)")
5590 let oldbufname= bufname(bufnr("%"))
5591" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5592
5593 if oldbufname != a:newname
5594" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5595 let b:junk= 1
5596" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5597 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005598" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005599 let oldbufnr= bufnr(oldbufname)
5600" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5601" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5602 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5603" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5604 exe "bwipe! ".oldbufnr
5605" else " Decho
5606" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005607" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5608" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5609" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005610 endif
5611" call Dredir("ls!","s:NetrwBufRename (after rename)")
5612" else " Decho
5613" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5614 endif
5615
5616" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5617endfun
5618
5619" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005620" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005621fun! netrw#CheckIfRemote(...)
5622" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5623 if a:0 > 0
5624 let curfile= a:1
5625 else
5626 let curfile= expand("%")
5627 endif
5628" call Decho("curfile<".curfile.">")
5629 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005630" call Dret("netrw#CheckIfRemote 1")
5631 return 1
5632 else
5633" call Dret("netrw#CheckIfRemote 0")
5634 return 0
5635 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005636endfun
5637
5638" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005639" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5640fun! s:NetrwChgPerm(islocal,curdir)
5641" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005642 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005643 call inputsave()
5644 let newperm= input("Enter new permission: ")
5645 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005646 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5647 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5648" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 call system(chgperm)
5650 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005651 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005652 endif
5653 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005654 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005656 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657" call Dret("s:NetrwChgPerm")
5658endfun
5659
5660" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005661" s:CheckIfKde: checks if kdeinit is running {{{2
5662" Returns 0: kdeinit not running
5663" 1: kdeinit is running
5664fun! s:CheckIfKde()
5665" call Dfunc("s:CheckIfKde()")
5666 " seems kde systems often have gnome-open due to dependencies, even though
5667 " gnome-open's subsidiary display tools are largely absent. Kde systems
5668 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5669 if !exists("s:haskdeinit")
5670 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005671 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005672 if v:shell_error
5673 let s:haskdeinit = 0
5674 endif
5675 else
5676 let s:haskdeinit= 0
5677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005678" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 endif
5680
5681" call Dret("s:CheckIfKde ".s:haskdeinit)
5682 return s:haskdeinit
5683endfun
5684
5685" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005686" s:NetrwClearExplore: clear explore variables (if any) {{{2
5687fun! s:NetrwClearExplore()
5688" call Dfunc("s:NetrwClearExplore()")
5689 2match none
5690 if exists("s:explore_match") |unlet s:explore_match |endif
5691 if exists("s:explore_indx") |unlet s:explore_indx |endif
5692 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5693 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5694 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5695 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5696 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5697 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5698 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5699" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005700" call Dret("s:NetrwClearExplore")
5701endfun
5702
5703" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005704" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5705fun! s:NetrwEditBuf(bufnum)
5706" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5707 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5708" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5709 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5710 else
5711" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005712 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005713 endif
5714" call Dret("s:NetrwEditBuf")
5715endfun
5716
5717" ---------------------------------------------------------------------
5718" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5719" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5720fun! s:NetrwEditFile(cmd,opt,fname)
5721" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5722 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5723" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5724 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5725 else
5726" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005727 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5728 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5729 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005730 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5731 endif
5732" call Dret("s:NetrwEditFile")
5733endfun
5734
5735" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005736" s:NetrwExploreListUniq: {{{2
5737fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005738" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005739
5740 " this assumes that the list is already sorted
5741 let newexplist= []
5742 for member in a:explist
5743 if !exists("uniqmember") || member != uniqmember
5744 let uniqmember = member
5745 let newexplist = newexplist + [ member ]
5746 endif
5747 endfor
5748
Bram Moolenaar15146672011-10-20 22:22:38 +02005749" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005750 return newexplist
5751endfun
5752
5753" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005754" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5755fun! s:NetrwForceChgDir(islocal,newdir)
5756" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005757 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005758 if a:newdir !~ '/$'
5759 " ok, looks like force is needed to get directory-style treatment
5760 if a:newdir =~ '@$'
5761 let newdir= substitute(a:newdir,'@$','/','')
5762 elseif a:newdir =~ '[*=|\\]$'
5763 let newdir= substitute(a:newdir,'.$','/','')
5764 else
5765 let newdir= a:newdir.'/'
5766 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005767" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005768 else
5769 " should already be getting treatment as a directory
5770 let newdir= a:newdir
5771 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005772 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005773 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005774 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005775" call Dret("s:NetrwForceChgDir")
5776endfun
5777
5778" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005779" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005780" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5781" expr : this is the expression to follow the directory. Will use s:ComposePath()
5782" pare =1: remove the current directory from the resulting glob() filelist
5783" =0: leave the current directory in the resulting glob() filelist
5784fun! s:NetrwGlob(direntry,expr,pare)
5785" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005786 if netrw#CheckIfRemote()
5787 keepalt 1sp
5788 keepalt enew
5789 let keep_liststyle = w:netrw_liststyle
5790 let w:netrw_liststyle = s:THINLIST
5791 if s:NetrwRemoteListing() == 0
5792 keepj keepalt %s@/@@
5793 let filelist= getline(1,$)
5794 q!
5795 else
5796 " remote listing error -- leave treedict unchanged
5797 let filelist= w:netrw_treedict[a:direntry]
5798 endif
5799 let w:netrw_liststyle= keep_liststyle
5800 else
Christian Brabandt14879472024-06-13 21:25:35 +02005801 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005802 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005803 " escape [ so it is not detected as wildcard character, see :h wildcard
5804 let path= substitute(path, '[', '[[]', 'g')
5805 endif
5806 if v:version > 704 || (v:version == 704 && has("patch656"))
5807 let filelist= glob(path,0,1,1)
5808 else
5809 let filelist= glob(path,0,1)
5810 endif
5811 if a:pare
5812 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5813 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005814 endif
5815" call Dret("s:NetrwGlob ".string(filelist))
5816 return filelist
5817endfun
5818
5819" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005820" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5821fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005822" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005823 if a:newfile =~ '[/@*=|\\]$'
5824 let newfile= substitute(a:newfile,'.$','','')
5825 else
5826 let newfile= a:newfile
5827 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005828 if a:islocal
5829 call s:NetrwBrowseChgDir(a:islocal,newfile)
5830 else
5831 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5832 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005833" call Dret("s:NetrwForceFile")
5834endfun
5835
5836" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005837" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5838" and switches the hiding mode. The actual hiding is done by
5839" s:NetrwListHide().
5840" g:netrw_hide= 0: show all
5841" 1: show not-hidden files
5842" 2: show hidden files only
5843fun! s:NetrwHide(islocal)
5844" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005845 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005846 let svpos= winsaveview()
5847" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005848
5849 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005850" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5851" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005852
5853 " hide the files in the markfile list
5854 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005855" 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 +00005856 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5857 " remove fname from hiding list
5858 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5859 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5860 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005861" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862 else
5863 " append fname to hiding list
5864 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5865 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5866 else
5867 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5868 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005869" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870 endif
5871 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005872 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873 let g:netrw_hide= 1
5874
5875 else
5876
5877 " switch between show-all/show-not-hidden/show-hidden
5878 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005879 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005882 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005883" call Dret("NetrwHide")
5884 return
5885 endif
5886 endif
5887
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005888 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005889" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5890 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005891 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005893endfun
5894
5895" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005896" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5897fun! s:NetrwHideEdit(islocal)
5898" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5899
5900 let ykeep= @@
5901 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005902 let svpos= winsaveview()
5903" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005904
5905 " get new hiding list from user
5906 call inputsave()
5907 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5908 call inputrestore()
5909 let g:netrw_list_hide= newhide
5910" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5911
5912 " refresh the listing
5913 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5914
5915 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005916" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5917 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005918 let @@= ykeep
5919
5920" call Dret("NetrwHideEdit")
5921endfun
5922
5923" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005924" s:NetrwHidden: invoked by "gh" {{{2
5925fun! s:NetrwHidden(islocal)
5926" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005927 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005929 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005930" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931
5932 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005933 " remove .file pattern from hiding list
5934" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005935 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005936 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005937" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5939 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005940" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005941 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5942 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005943 if g:netrw_list_hide =~ '^,'
5944 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5945 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005946
5947 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005948 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005949" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5950 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005951 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005952" call Dret("s:NetrwHidden")
5953endfun
5954
5955" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005956" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5957fun! s:NetrwHome()
5958 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005959 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005960 else
5961 " go to vim plugin home
5962 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005963 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005964 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005965 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005966 let home= basehome."/.vim"
5967 break
5968 endif
5969 endfor
5970 if home == ""
5971 " just pick the first directory
5972 let home= substitute(&rtp,',.*$','','')
5973 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005974 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005975 let home= substitute(home,'/','\\','g')
5976 endif
5977 endif
5978 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005979 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005980" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005981 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005983 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005984 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005985" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005986 call mkdir(home)
5987 endif
5988 endif
5989 let g:netrw_home= home
5990 return home
5991endfun
5992
5993" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005994" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5995fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005996 if exists("s:netrwdrag")
5997 return
5998 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005999 if &ft != "netrw"
6000 return
6001 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006002" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006003
Bram Moolenaar97d62492012-11-15 21:28:22 +01006004 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006005 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006006 while getchar(0) != 0
6007 "clear the input stream
6008 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006009 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006010 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006011 let mouse_lnum = v:mouse_lnum
6012 let wlastline = line('w$')
6013 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006014" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6015" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006016 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6017 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006018 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006019" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6020 return
6021 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006022 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006023 " 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 +01006024 " without this test when its disabled.
6025 " 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 +01006026" 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 +01006027 if v:mouse_col > virtcol('.')
6028 let @@= ykeep
6029" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6030 return
6031 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006032
Bram Moolenaar446cb832008-06-24 21:56:24 +00006033 if a:islocal
6034 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006035 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006036 endif
6037 else
6038 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006039 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006040 endif
6041 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006042 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006043" call Dret("s:NetrwLeftmouse")
6044endfun
6045
6046" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006047" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6048fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006049 if &ft != "netrw"
6050 return
6051 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006052" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6053 call s:NetrwMarkFileTgt(a:islocal)
6054" call Dret("s:NetrwCLeftmouse")
6055endfun
6056
6057" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006058" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6059" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006060" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061" a:islocal=2 : <c-r> used, remote
6062" a:islocal=3 : <c-r> used, local
6063fun! s:NetrwServerEdit(islocal,fname)
6064" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6065 let islocal = a:islocal%2 " =0: remote =1: local
6066 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006067" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006069 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006071 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006072" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006073 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006074 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6076 unlet s:netrw_browse_split_{winnr()}
6077 endif
6078 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6079" call Dret("s:NetrwServerEdit")
6080 return
6081 endif
6082
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006083" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006084 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086
6087 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006088" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006089 let srvrname = g:netrw_browse_split[0]
6090 let tabnum = g:netrw_browse_split[1]
6091 let winnum = g:netrw_browse_split[2]
6092
6093 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006094" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095
6096 if !ctrlr
6097 " user must have closed the server window and the user did not use <c-r>, but
6098 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006099" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006100 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006101 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 endif
6103 let g:netrw_browse_split= 0
6104 if exists("s:netrw_browse_split_".winnr())
6105 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6106 endif
6107 call s:NetrwBrowseChgDir(islocal,a:fname)
6108" call Dret("s:NetrwServerEdit")
6109 return
6110
6111 elseif has("win32") && executable("start")
6112 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006114 call system("start gvim --servername ".srvrname)
6115
6116 else
6117 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006118" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006119 call system("gvim --servername ".srvrname)
6120 endif
6121 endif
6122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6125 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127
6128 else
6129
6130 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6131
6132 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006133" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006134 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006135 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 endif
6137 let g:netrw_browse_split= 0
6138 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6139" call Dret("s:NetrwServerEdit")
6140 return
6141
6142 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006143" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006144 if has("win32") && executable("start")
6145 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006147 call system("start gvim --servername ".g:netrw_servername)
6148 else
6149 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006150" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 call system("gvim --servername ".g:netrw_servername)
6152 endif
6153 endif
6154 endif
6155
6156 while 1
6157 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006158" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6159 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006160 break
6161 catch /^Vim\%((\a\+)\)\=:E241/
6162 sleep 200m
6163 endtry
6164 endwhile
6165
6166 if exists("g:netrw_browse_split")
6167 if type(g:netrw_browse_split) != 3
6168 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6169 endif
6170 unlet g:netrw_browse_split
6171 endif
6172 let g:netrw_browse_split= [g:netrw_servername,1,1]
6173 endif
6174
6175 else
6176 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6177 endif
6178
6179" call Dret("s:NetrwServerEdit")
6180endfun
6181
6182" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006183" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6184fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006185 if &ft != "netrw"
6186 return
6187 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006188" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006189
Bram Moolenaar8d043172014-01-23 14:24:41 +01006190 let s:ngw= s:NetrwGetWord()
6191 call s:NetrwMarkFile(a:islocal,s:ngw)
6192
6193" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006194endfun
6195
6196" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006197" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6198" Used to mark multiple files.
6199fun! s:NetrwSLeftdrag(islocal)
6200" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6201 if !exists("s:netrwdrag")
6202 let s:netrwdrag = winnr()
6203 if a:islocal
6204 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006205 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006206 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006207 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006208 endif
6209 let ngw = s:NetrwGetWord()
6210 if !exists("s:ngw") || s:ngw != ngw
6211 call s:NetrwMarkFile(a:islocal,ngw)
6212 endif
6213 let s:ngw= ngw
6214" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6215endfun
6216
6217" ---------------------------------------------------------------------
6218" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6219fun! s:NetrwSLeftrelease(islocal)
6220" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6221 if exists("s:netrwdrag")
6222 nunmap <s-leftrelease>
6223 let ngw = s:NetrwGetWord()
6224 if !exists("s:ngw") || s:ngw != ngw
6225 call s:NetrwMarkFile(a:islocal,ngw)
6226 endif
6227 if exists("s:ngw")
6228 unlet s:ngw
6229 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006230 unlet s:netrwdrag
6231 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006232" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006233endfun
6234
6235" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006236" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6237" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006238fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006239" 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 +02006240" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006241 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006242
6243 " 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 +02006244 " How-it-works: take the hiding command, convert it into a range.
6245 " Duplicate characters don't matter.
6246 " Remove all such characters from the '/~@#...890' string.
6247 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006248" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006249 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006250 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006251" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252
6253 while listhide != ""
6254 if listhide =~ ','
6255 let hide = substitute(listhide,',.*$','','e')
6256 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6257 else
6258 let hide = listhide
6259 let listhide = ""
6260 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006261" 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 +01006262 if g:netrw_sort_by =~ '^[ts]'
6263 if hide =~ '^\^'
6264" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6265 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6266 elseif hide =~ '^\\(\^'
6267 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6268 endif
6269" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6270 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271
6272 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006273" 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 +00006274 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006275" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006276 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006278" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006279 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006280 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006281" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006282 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006283
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006285 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006286" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006287 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289 endif
6290
Bram Moolenaaradc21822011-04-01 18:03:16 +02006291 " remove any blank lines that have somehow remained.
6292 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006293 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006294
Bram Moolenaar97d62492012-11-15 21:28:22 +01006295 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006296" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297endfun
6298
6299" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006301" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006303" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304
Bram Moolenaar97d62492012-11-15 21:28:22 +01006305 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 " get name of new directory from user. A bare <CR> will skip.
6307 " if its currently a directory, also request will be skipped, but with
6308 " a message.
6309 call inputsave()
6310 let newdirname= input("Please give directory name: ")
6311 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006312" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313
6314 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006315 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006316" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317 return
6318 endif
6319
6320 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006321" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006322
6323 " Local mkdir:
6324 " sanity checks
6325 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006326" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6327 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006329 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006330 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006331 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006332" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333 return
6334 endif
6335 if s:FileReadable(fullnewdir)
6336 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006337 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006339 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006340" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006341 return
6342 endif
6343
6344 " requested new local directory is neither a pre-existing file or
6345 " directory, so make it!
6346 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006347 if has("unix")
6348 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6349 else
6350 call mkdir(fullnewdir,"p")
6351 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006352 else
6353 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006354 if s:NetrwLcd(b:netrw_curdir)
6355" call Dret("s:NetrwMakeDir : lcd failure")
6356 return
6357 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006359 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006360 if v:shell_error != 0
6361 let @@= ykeep
6362 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 +01006363" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006364 return
6365 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006366 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006368 if s:NetrwLcd(netrw_origdir)
6369" call Dret("s:NetrwBrowse : lcd failure")
6370 return
6371 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006372 endif
6373 endif
6374
6375 if v:shell_error == 0
6376 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006377" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006378 let svpos= winsaveview()
6379" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006380 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006381" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6382 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006383 elseif !exists("g:netrw_quiet")
6384 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6385 endif
6386" redraw!
6387
6388 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006389 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006390" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006391 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6392 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006393 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006394 if v:shell_error == 0
6395 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006396 let svpos= winsaveview()
6397" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006398 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006399" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6400 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006402 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 endif
6404" redraw!
6405
6406 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006407 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006408 let svpos= winsaveview()
6409" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006410" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006411 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006412" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 let remotepath= b:netrw_fname
6414 else
6415 let remotepath= ""
6416 endif
6417 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006418 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006419" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6420 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006421
Bram Moolenaar446cb832008-06-24 21:56:24 +00006422 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006423 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006424 let svpos= winsaveview()
6425" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006426" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006427 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 let remotepath= b:netrw_fname
6430 else
6431 let remotepath= ""
6432 endif
6433 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006434 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006435" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6436 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437 endif
6438
Bram Moolenaar97d62492012-11-15 21:28:22 +01006439 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006440" call Dret("s:NetrwMakeDir")
6441endfun
6442
6443" ---------------------------------------------------------------------
6444" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6445fun! s:TreeSqueezeDir(islocal)
6446" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6447 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6448 " its a tree-listing style
6449 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006450 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006451 let depth = strchars(substitute(curdepth,' ','','g'))
6452 let srch = -1
6453" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6454" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006455" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006456" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6457 if depth >= 2
6458 NetrwKeepj norm! 0
6459 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6460 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6461" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6462" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6463 elseif depth == 1
6464 NetrwKeepj norm! 0
6465 let treedepthchr= substitute(s:treedepthstring,' ','','')
6466 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6467" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6468 endif
6469 if srch > 0
6470" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6471 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6472 exe srch
6473 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006474 endif
6475" call Dret("s:TreeSqueezeDir")
6476endfun
6477
6478" ---------------------------------------------------------------------
6479" s:NetrwMaps: {{{2
6480fun! s:NetrwMaps(islocal)
6481" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6482
Bram Moolenaar85850f32019-07-19 22:05:51 +02006483 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006484 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 if !hasmapto("<Plug>NetrwReturn")
6487 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006488" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6490 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006491" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006492 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6493 endif
6494 endif
6495 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006496" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006497 endif
6498
Bram Moolenaar85850f32019-07-19 22:05:51 +02006499 " generate default <Plug> maps {{{3
6500 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006501 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006502 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6503 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6504 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6505 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6506 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6507 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6508 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6509 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6510 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6511 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6512" ---------------------------------------------------------------------
6513" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6514" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6515" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6516" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6517" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6518" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6519" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6520" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6521" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6522" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6523" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6524" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6525" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6526" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6527" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6528" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6529" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6530" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6531" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6532" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6533" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6534" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6535" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6536" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6537" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6538" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6539" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6540" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6541" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6542" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6543" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6544" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6545" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6546" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6547" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6548" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6549" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6550" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6551" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6552" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6553" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6554" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6555" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6556" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6557" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6558" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6559" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6560
Bram Moolenaara6878372014-03-22 21:02:50 +01006561 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006562" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006563 " local normal-mode maps {{{3
6564 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6565 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6566 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6575" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006576 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6577 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6578 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006579 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006580 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006581 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6582 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6583 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6584 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006585 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6586 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6587 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6589 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6591 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6592 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006598 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006599 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6602 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6603 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6604 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006605 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006606 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6608 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006609 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6610 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6611 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006612 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006613 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6615 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006617 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6619 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6620 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006621 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6622 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006623
6624 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 +01006625 if !hasmapto('<Plug>NetrwHideEdit')
6626 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006627 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006628 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006629 if !hasmapto('<Plug>NetrwRefresh')
6630 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006632 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 +01006633 if s:didstarstar || !mapcheck("<s-down>","n")
6634 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006635 endif
6636 if s:didstarstar || !mapcheck("<s-up>","n")
6637 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006638 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006639 if !hasmapto('<Plug>NetrwTreeSqueeze')
6640 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 endif
6642 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006643 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6644 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006645 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6646 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6647 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6648 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6649 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6650 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6651 imap <buffer> <leftmouse> <Plug>ILeftmouse
6652 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006653 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6654 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6655 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6656 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6657 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006658 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006659 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6660 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006661 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006662 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6663 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6664 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6665 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6666 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6667 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6668 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006669 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6670
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006671 " support user-specified maps
6672 call netrw#UserMaps(1)
6673
Bram Moolenaar85850f32019-07-19 22:05:51 +02006674 else
6675 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006676" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006678 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6679 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6680 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6689" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006690 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6691 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6692 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6693 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6694 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6695 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6696 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6697 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006698 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006699 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006700 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6702 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6704 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6705 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006711 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006712 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6716 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6717 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006718 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6721 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006722 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006723 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6724 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006725 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006726 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 +01006727 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6729 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6730 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6731 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6732 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6733 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6734 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6735 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006736 if !hasmapto('<Plug>NetrwHideEdit')
6737 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006738 endif
6739 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6740 if !hasmapto('<Plug>NetrwRefresh')
6741 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006742 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006743 if !hasmapto('<Plug>NetrwTreeSqueeze')
6744 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006745 endif
6746 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006747
6748 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006749 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006750
6751 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6752 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006753 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006754 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006756 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006758 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006760 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006762 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6764 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6765 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006767 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006768 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6769 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006770 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6772 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6773 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6775 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6777 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006778 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006779
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006780 " support user-specified maps
6781 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006782 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006783
6784" call Dret("s:NetrwMaps")
6785endfun
6786
6787" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006788" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006789" If -buffer, the command is only available from within netrw buffers
6790" Otherwise, the command is available from any window, so long as netrw
6791" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006792fun! s:NetrwCommands(islocal)
6793" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6794
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006795 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6796 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006797 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 +01006798 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006799 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006800 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006801 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006802 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006803 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006804
6805" call Dret("s:NetrwCommands")
6806endfun
6807
6808" ---------------------------------------------------------------------
6809" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6810" glob()ing only works with local files
6811fun! s:NetrwMarkFiles(islocal,...)
6812" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006813 let curdir = s:NetrwGetCurdir(a:islocal)
6814 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006815 while i <= a:0
6816 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006817 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006818 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006819 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006820 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006821 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006822 else
6823 let mffiles= [a:{i}]
6824 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006825" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006826 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006828 call s:NetrwMarkFile(a:islocal,mffile)
6829 endfor
6830 let i= i + 1
6831 endwhile
6832" call Dret("s:NetrwMarkFiles")
6833endfun
6834
6835" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006836" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006837fun! s:NetrwMarkTarget(...)
6838" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6839 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840 let curdir = s:NetrwGetCurdir(1)
6841 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006842 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006843 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6844 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006845 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006846" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6849 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006850 let svpos = winsaveview()
6851" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006852 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006853" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6854 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006855" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006856endfun
6857
6858" ---------------------------------------------------------------------
6859" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6860" mark and unmark files. If a markfile list exists,
6861" then the rename and delete functions will use it instead
6862" of whatever may happen to be under the cursor at that
6863" moment. When the mouse and gui are available,
6864" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006865"
6866" Creates two lists
6867" s:netrwmarkfilelist -- holds complete paths to all marked files
6868" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6869"
6870" Creates a marked file match string
6871" s:netrwmarfilemtch_# -- used with 2match to display marked files
6872"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006873" Creates a buffer version of islocal
6874" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006875fun! s:NetrwMarkFile(islocal,fname)
6876" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006877" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006878
6879 " sanity check
6880 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006881" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006882 return
6883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006884 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006885
Bram Moolenaar97d62492012-11-15 21:28:22 +01006886 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006887 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006888 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006889 if a:fname =~ '\a$'
6890 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6891 else
6892 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6893 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006894
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006895 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006896 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006897" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6898" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6899" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006900 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901
6902 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006903 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006904" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006905 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006906 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907
6908 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006909 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6912 if s:netrwmarkfilelist_{curbufnr} == []
6913 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006914" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006915 call s:NetrwUnmarkList(curbufnr,curdir)
6916 else
6917 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006918" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006919 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006920 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 for fname in s:netrwmarkfilelist_{curbufnr}
6922 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006923 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006925 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006926 endif
6927 let first= 0
6928 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006929" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 endif
6931 endif
6932
6933 else
6934 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006937" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006939 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6940" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941
6942 " build initial markfile matching pattern
6943 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006944 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006945 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006946 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006948" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006949 endif
6950
6951 " handle global markfilelist
6952 if exists("s:netrwmarkfilelist")
6953 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6954 if index(s:netrwmarkfilelist,dname) == -1
6955 " append new filename to global markfilelist
6956 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006957" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958 else
6959 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6961" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006962 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006965" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006966 unlet s:netrwmarkfilelist
6967 endif
6968 endif
6969 else
6970 " initialize new global-directory markfilelist
6971 let s:netrwmarkfilelist= []
6972 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006973" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974 endif
6975
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006976 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006977 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6978 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6979" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6980 if exists("g:did_drchip_netrwlist_syntax")
6981 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6982 endif
6983 else
6984" " call Decho("2match none",'~'.expand("<slnum>"))
6985 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006986 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006987 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006988 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006989" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6990" 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 +00006991endfun
6992
6993" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006994" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6995" mA: move the argument list to marked file list (tomflist=1)
6996" Uses the global marked file list
6997fun! s:NetrwMarkFileArgList(islocal,tomflist)
6998" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6999
7000 let svpos = winsaveview()
7001" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7002 let curdir = s:NetrwGetCurdir(a:islocal)
7003 let curbufnr = bufnr("%")
7004
7005 if a:tomflist
7006 " mA: move argument list to marked file list
7007 while argc()
7008 let fname= argv(0)
7009" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7010 exe "argdel ".fnameescape(fname)
7011 call s:NetrwMarkFile(a:islocal,fname)
7012 endwhile
7013
7014 else
7015 " ma: move marked file list to argument list
7016 if exists("s:netrwmarkfilelist")
7017
7018 " for every filename in the marked list
7019 for fname in s:netrwmarkfilelist
7020" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7021 exe "argadd ".fnameescape(fname)
7022 endfor " for every file in the marked list
7023
7024 " unmark list and refresh
7025 call s:NetrwUnmarkList(curbufnr,curdir)
7026 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7027" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7028 NetrwKeepj call winrestview(svpos)
7029 endif
7030 endif
7031
7032" call Dret("s:NetrwMarkFileArgList")
7033endfun
7034
7035" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007036" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7037" compress/decompress files using the programs
7038" in g:netrw_compress and g:netrw_uncompress,
7039" using g:netrw_compress_suffix to know which to
7040" do. By default:
7041" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007042" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007043fun! s:NetrwMarkFileCompress(islocal)
7044" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007045 let svpos = winsaveview()
7046" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007047 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007048 let curbufnr = bufnr("%")
7049
Bram Moolenaarff034192013-04-24 18:51:19 +02007050 " sanity check
7051 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007052 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007053" call Dret("s:NetrwMarkFileCompress")
7054 return
7055 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007056" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007057
Bram Moolenaar446cb832008-06-24 21:56:24 +00007058 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007059
7060 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007062 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007063" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007064 if exists("g:netrw_decompress['".sfx."']")
7065 " fname has a suffix indicating that its compressed; apply associated decompression routine
7066 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007067" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 let exe= netrw#WinPath(exe)
7069 if a:islocal
7070 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007071 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007073 call system(exe." ".fname)
7074 if v:shell_error
7075 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007076 endif
7077 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007078 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7079 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007080 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007081
Bram Moolenaarff034192013-04-24 18:51:19 +02007082 endif
7083 unlet sfx
7084
Bram Moolenaar446cb832008-06-24 21:56:24 +00007085 if exists("exe")
7086 unlet exe
7087 elseif a:islocal
7088 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007090 if v:shell_error
7091 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7092 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007093 else
7094 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007095 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007097 endfor " for every file in the marked list
7098
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007100 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007101" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7102 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103 endif
7104" call Dret("s:NetrwMarkFileCompress")
7105endfun
7106
7107" ---------------------------------------------------------------------
7108" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7109" If no marked files, then set up directory as the
7110" target. Currently does not support copying entire
7111" directories. Uses the local-buffer marked file list.
7112" Returns 1=success (used by NetrwMarkFileMove())
7113" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007114fun! s:NetrwMarkFileCopy(islocal,...)
7115" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7116
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007117 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007118 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007119 if b:netrw_curdir !~ '/$'
7120 if !exists("b:netrw_curdir")
7121 let b:netrw_curdir= curdir
7122 endif
7123 let b:netrw_curdir= b:netrw_curdir."/"
7124 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007125
Bram Moolenaarff034192013-04-24 18:51:19 +02007126 " sanity check
7127 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007128 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007129" call Dret("s:NetrwMarkFileCopy")
7130 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007132" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007133
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007135 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007136" call Dret("s:NetrwMarkFileCopy 0")
7137 return 0
7138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007139" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007140
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007141 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007143" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007144 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007145 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7146" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7147 return
7148 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007149
7150 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007151 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007152 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7153 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007154" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007155 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007156 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7157 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007158" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007160 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007161 let oldname = a:1
7162 else
7163 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007164" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165 let s:recursive= 1
7166 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7167 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7168 if ret == 0
7169 break
7170 endif
7171 endfor
7172 unlet s:recursive
7173 call s:NetrwUnmarkList(curbufnr,curdir)
7174" call Dret("s:NetrwMarkFileCopy ".ret)
7175 return ret
7176 endif
7177
7178 call inputsave()
7179 let newname= input("Copy ".oldname." to : ",oldname,"file")
7180 call inputrestore()
7181 if newname == ""
7182" call Dret("s:NetrwMarkFileCopy 0")
7183 return 0
7184 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007185 let args= s:ShellEscape(oldname)
7186 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007187 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007188 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7189 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007190 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007191 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007192 let args= substitute(args,'/','\\','g')
7193 let tgt = substitute(tgt, '/','\\','g')
7194 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007195 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7196 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7197 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7198 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7199" call Decho("args <".args.">",'~'.expand("<slnum>"))
7200" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007201 if isdirectory(s:NetrwFile(args))
7202" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007203 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007205 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7207 " contents to a target. One must append the source directory name to the target to get xcopy to
7208 " do the right thing.
7209 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007211 endif
7212 else
7213 let copycmd= g:netrw_localcopycmd
7214 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007215 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007216 let copycmd = substitute(copycmd,'\s.*$','','')
7217 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 let copycmd = netrw#WinPath(copycmd).copycmdargs
7219 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007220 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007222" call Decho("args <".args.">",'~'.expand("<slnum>"))
7223" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7224" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7225" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007226 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007227 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007228 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007229 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 +01007230 else
7231 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7232 endif
7233" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007234 return 0
7235 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007236
7237 elseif a:islocal && !s:netrwmftgt_islocal
7238 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007239" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007241
7242 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007243 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007245 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246
7247 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007248 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007249" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007250 let curdir = getcwd()
7251 let tmpdir = s:GetTempfile("")
7252 if tmpdir !~ '/'
7253 let tmpdir= curdir."/".tmpdir
7254 endif
7255 if exists("*mkdir")
7256 call mkdir(tmpdir)
7257 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007258 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007259 if v:shell_error != 0
7260 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 +01007261" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007262 return
7263 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007264 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007265 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007266 if s:NetrwLcd(tmpdir)
7267" call Dret("s:NetrwMarkFileCopy : lcd failure")
7268 return
7269 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007270 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007271 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007272 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007273 if getcwd() == tmpdir
7274 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007277 if s:NetrwLcd(curdir)
7278" call Dret("s:NetrwMarkFileCopy : lcd failure")
7279 return
7280 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007281 if delete(tmpdir,"d")
7282 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007283 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007284 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007285 if s:NetrwLcd(curdir)
7286" call Dret("s:NetrwMarkFileCopy : lcd failure")
7287 return
7288 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007289 endif
7290 endif
7291 endif
7292
7293 " -------
7294 " cleanup
7295 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007296" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007297 " remove markings from local buffer
7298 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007299" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7300" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7301" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7302" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7303" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7304" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7305 if exists("s:recursive")
7306" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7307 else
7308" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007309 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007310 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007311 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007312 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007313 else
7314 " refresh local and targets for fast browsing
7315 if !exists("s:recursive")
7316 " remove markings from local buffer
7317" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7318 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7319 endif
7320
7321 " refresh buffers
7322 if s:netrwmftgt_islocal
7323" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7324 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7325 endif
7326 if a:islocal && s:netrwmftgt != curdir
7327" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7328 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7329 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007330 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007331
Bram Moolenaar446cb832008-06-24 21:56:24 +00007332" call Dret("s:NetrwMarkFileCopy 1")
7333 return 1
7334endfun
7335
7336" ---------------------------------------------------------------------
7337" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7338" invoke vim's diff mode on the marked files.
7339" Either two or three files can be so handled.
7340" Uses the global marked file list.
7341fun! s:NetrwMarkFileDiff(islocal)
7342" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7343 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007344
Bram Moolenaarff034192013-04-24 18:51:19 +02007345 " sanity check
7346 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007347 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007348" call Dret("s:NetrwMarkFileDiff")
7349 return
7350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007351 let curdir= s:NetrwGetCurdir(a:islocal)
7352" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007353
Bram Moolenaara6878372014-03-22 21:02:50 +01007354 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007355 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007356 for fname in s:netrwmarkfilelist
7357 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007359" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007360 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 diffthis
7362 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007363 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007365 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007366 diffthis
7367 else
7368 break
7369 endif
7370 endfor
7371 call s:NetrwUnmarkList(curbufnr,curdir)
7372 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007373
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374" call Dret("s:NetrwMarkFileDiff")
7375endfun
7376
7377" ---------------------------------------------------------------------
7378" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7379" Uses global markfilelist
7380fun! s:NetrwMarkFileEdit(islocal)
7381" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7382
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007383 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007385
7386 " sanity check
7387 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007388 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007389" call Dret("s:NetrwMarkFileEdit")
7390 return
7391 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007393
Bram Moolenaar446cb832008-06-24 21:56:24 +00007394 if exists("s:netrwmarkfilelist_{curbufnr}")
7395 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007396 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 " unmark markedfile list
7398" call s:NetrwUnmarkList(curbufnr,curdir)
7399 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007400" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007401 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007402 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007403 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007404
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405" call Dret("s:NetrwMarkFileEdit")
7406endfun
7407
7408" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007409" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007410fun! s:NetrwMarkFileQFEL(islocal,qfel)
7411" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7412 call s:NetrwUnmarkAll()
7413 let curbufnr= bufnr("%")
7414
7415 if !empty(a:qfel)
7416 for entry in a:qfel
7417 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007418" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007419 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007420" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007421 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7422 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7423 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7424 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007426 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7427 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007429 endif
7430 endfor
7431 echo "(use me to edit marked files)"
7432 else
7433 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7434 endif
7435
7436" call Dret("s:NetrwMarkFileQFEL")
7437endfun
7438
7439" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007440" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7441" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7442" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7443fun! s:NetrwMarkFileExe(islocal,enbloc)
7444" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007445 let svpos = winsaveview()
7446" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007447 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007448 let curbufnr = bufnr("%")
7449
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007450 if a:enbloc == 0
7451 " individually apply command to files, one at a time
7452 " sanity check
7453 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7454 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7455" call Dret("s:NetrwMarkFileExe")
7456 return
7457 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007458" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007459
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007460 if exists("s:netrwmarkfilelist_{curbufnr}")
7461 " get the command
7462 call inputsave()
7463 let cmd= input("Enter command: ","","file")
7464 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007465" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 if cmd == ""
7467" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7468 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007469 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007470
7471 " apply command to marked files, individually. Substitute: filename -> %
7472 " If no %, then append a space and the filename to the command
7473 for fname in s:netrwmarkfilelist_{curbufnr}
7474 if a:islocal
7475 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007476 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007477 endif
7478 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007479 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007480 endif
7481 if cmd =~ '%'
7482 let xcmd= substitute(cmd,'%',fname,'g')
7483 else
7484 let xcmd= cmd.' '.fname
7485 endif
7486 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007487" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007488 let ret= system(xcmd)
7489 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007490" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 let ret= s:RemoteSystem(xcmd)
7492 endif
7493 if v:shell_error < 0
7494 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7495 break
7496 else
yasudac75dad02024-08-22 21:06:32 +02007497 if ret !=# ''
7498 echo "\n"
7499 " skip trailing new line
7500 echo ret[0:-2]
7501 else
7502 echo ret
7503 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007504 endif
7505 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506
7507 " unmark marked file list
7508 call s:NetrwUnmarkList(curbufnr,curdir)
7509
7510 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007512" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7513 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007517
7518 else " apply command to global list of files, en bloc
7519
7520 call inputsave()
7521 let cmd= input("Enter command: ","","file")
7522 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 if cmd == ""
7525" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7526 return
7527 endif
7528 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007531 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007532 endif
7533 if a:islocal
7534 call system(cmd)
7535 if v:shell_error < 0
7536 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7537 endif
7538 else
7539 let ret= s:RemoteSystem(cmd)
7540 endif
7541 call s:NetrwUnmarkAll()
7542
7543 " refresh the listing
7544 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007545" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7546 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547
7548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007549
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550" call Dret("s:NetrwMarkFileExe")
7551endfun
7552
7553" ---------------------------------------------------------------------
7554" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7555" as the marked file(s) (toggles suffix presence)
7556" Uses the local marked file list.
7557fun! s:NetrwMarkHideSfx(islocal)
7558" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007559 let svpos = winsaveview()
7560" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007561 let curbufnr = bufnr("%")
7562
7563 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7564 if exists("s:netrwmarkfilelist_{curbufnr}")
7565
7566 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007567" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007568 " construct suffix pattern
7569 if fname =~ '\.'
7570 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7571 else
7572 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7573 endif
7574 " determine if its in the hiding list or not
7575 let inhidelist= 0
7576 if g:netrw_list_hide != ""
7577 let itemnum = 0
7578 let hidelist= split(g:netrw_list_hide,',')
7579 for hidepat in hidelist
7580 if sfxpat == hidepat
7581 let inhidelist= 1
7582 break
7583 endif
7584 let itemnum= itemnum + 1
7585 endfor
7586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007587" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 if inhidelist
7589 " remove sfxpat from list
7590 call remove(hidelist,itemnum)
7591 let g:netrw_list_hide= join(hidelist,",")
7592 elseif g:netrw_list_hide != ""
7593 " append sfxpat to non-empty list
7594 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7595 else
7596 " set hiding list to sfxpat
7597 let g:netrw_list_hide= sfxpat
7598 endif
7599 endfor
7600
7601 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007602 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007606 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 endif
7608
7609" call Dret("s:NetrwMarkHideSfx")
7610endfun
7611
7612" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007614" Uses the local marked-file list.
7615fun! s:NetrwMarkFileVimCmd(islocal)
7616" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007617 let svpos = winsaveview()
7618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 let curbufnr = bufnr("%")
7621
Bram Moolenaarff034192013-04-24 18:51:19 +02007622 " sanity check
7623 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007624 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007625" call Dret("s:NetrwMarkFileVimCmd")
7626 return
7627 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007628" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007629
Bram Moolenaar15146672011-10-20 22:22:38 +02007630 if exists("s:netrwmarkfilelist_{curbufnr}")
7631 " get the command
7632 call inputsave()
7633 let cmd= input("Enter vim command: ","","file")
7634 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007636 if cmd == ""
7637" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7638 return
7639 endif
7640
7641 " apply command to marked files. Substitute: filename -> %
7642 " If no %, then append a space and the filename to the command
7643 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 if a:islocal
7646 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007647 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 exe cmd
7650 exe "sil! keepalt wq!"
7651 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007654 endif
7655 endfor
7656
7657 " unmark marked file list
7658 call s:NetrwUnmarkList(curbufnr,curdir)
7659
7660 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007661 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007662" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7663 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007664 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007665 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007667
Bram Moolenaar15146672011-10-20 22:22:38 +02007668" call Dret("s:NetrwMarkFileVimCmd")
7669endfun
7670
7671" ---------------------------------------------------------------------
7672" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7673" as the marked file(s) (toggles suffix presence)
7674" Uses the local marked file list.
7675fun! s:NetrwMarkHideSfx(islocal)
7676" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007677 let svpos = winsaveview()
7678" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 let curbufnr = bufnr("%")
7680
7681 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7682 if exists("s:netrwmarkfilelist_{curbufnr}")
7683
7684 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007686 " construct suffix pattern
7687 if fname =~ '\.'
7688 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7689 else
7690 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7691 endif
7692 " determine if its in the hiding list or not
7693 let inhidelist= 0
7694 if g:netrw_list_hide != ""
7695 let itemnum = 0
7696 let hidelist= split(g:netrw_list_hide,',')
7697 for hidepat in hidelist
7698 if sfxpat == hidepat
7699 let inhidelist= 1
7700 break
7701 endif
7702 let itemnum= itemnum + 1
7703 endfor
7704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007705" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007706 if inhidelist
7707 " remove sfxpat from list
7708 call remove(hidelist,itemnum)
7709 let g:netrw_list_hide= join(hidelist,",")
7710 elseif g:netrw_list_hide != ""
7711 " append sfxpat to non-empty list
7712 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7713 else
7714 " set hiding list to sfxpat
7715 let g:netrw_list_hide= sfxpat
7716 endif
7717 endfor
7718
7719 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007720 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007721" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7722 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007723 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007724 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007725 endif
7726
7727" call Dret("s:NetrwMarkHideSfx")
7728endfun
7729
7730" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007731" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7732" Uses the global markfilelist
7733fun! s:NetrwMarkFileGrep(islocal)
7734" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007735 let svpos = winsaveview()
7736" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007738 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739
7740 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007741" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007742 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007743" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007745 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007746" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 let netrwmarkfilelist= "*"
7748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007751" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 call inputsave()
7753 let pat= input("Enter pattern: ","")
7754 call inputrestore()
7755 let patbang = ""
7756 if pat =~ '^!'
7757 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007758 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007759 endif
7760 if pat =~ '^\i'
7761 let pat = escape(pat,'/')
7762 let pat = '/'.pat.'/'
7763 else
7764 let nonisi = pat[0]
7765 endif
7766
7767 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007769 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007770 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007771 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007772 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007773" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7774 return
7775 endtry
7776 echo "(use :cn, :cp to navigate, :Rex to return)"
7777
7778 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007779" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7780 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007781
7782 if exists("nonisi")
7783 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007784" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007785 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007788 endif
7789
7790" call Dret("s:NetrwMarkFileGrep")
7791endfun
7792
7793" ---------------------------------------------------------------------
7794" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7795" uses the global marked file list
7796" s:netrwmfloc= 0: target directory is remote
7797" = 1: target directory is local
7798fun! s:NetrwMarkFileMove(islocal)
7799" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 let curbufnr = bufnr("%")
7802
7803 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007804 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806" call Dret("s:NetrwMarkFileMove")
7807 return
7808 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007810
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007812 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813" call Dret("s:NetrwMarkFileCopy 0")
7814 return 0
7815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817
7818 if a:islocal && s:netrwmftgt_islocal
7819 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("move from local to local",'~'.expand("<slnum>"))
7821" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007822 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007823 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7824" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7825 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007829 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007830 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007832 if g:netrw_localmovecmd =~ '\s'
7833 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7834 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7835 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007838 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007840 endif
7841 else
7842 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007845 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007846 if g:netrw_keepdir
7847 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7848 let fname= b:netrw_curdir."/".fname
7849 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007850 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007851 let fname= substitute(fname,'/','\\','g')
7852 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 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 +01007858 else
7859 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7860 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007861 break
7862 endif
7863 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007864
7865 elseif a:islocal && !s:netrwmftgt_islocal
7866 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867" call Decho("move from local to remote",'~'.expand("<slnum>"))
7868" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007870 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872 for fname in mflist
7873 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7874 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7875 endfor
7876 unlet mflist
7877
7878 elseif !a:islocal && s:netrwmftgt_islocal
7879 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("move from remote to local",'~'.expand("<slnum>"))
7881" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885 for fname in mflist
7886 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7887 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7888 endfor
7889 unlet mflist
7890
7891 elseif !a:islocal && !s:netrwmftgt_islocal
7892 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7894" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 for fname in mflist
7899 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7900 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7901 endfor
7902 unlet mflist
7903 endif
7904
7905 " -------
7906 " cleanup
7907 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007908" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909
7910 " remove markings from local buffer
7911 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7912
7913 " refresh buffers
7914 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007915" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007916 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007917 endif
7918 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007920 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007924 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927" call Dret("s:NetrwMarkFileMove")
7928endfun
7929
7930" ---------------------------------------------------------------------
7931" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7932" using the hardcopy command. Local marked-file list only.
7933fun! s:NetrwMarkFilePrint(islocal)
7934" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7935 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007936
7937 " sanity check
7938 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007939 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007940" call Dret("s:NetrwMarkFilePrint")
7941 return
7942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7944 let curdir= s:NetrwGetCurdir(a:islocal)
7945
Bram Moolenaar446cb832008-06-24 21:56:24 +00007946 if exists("s:netrwmarkfilelist_{curbufnr}")
7947 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 call s:NetrwUnmarkList(curbufnr,curdir)
7949 for fname in netrwmarkfilelist
7950 if a:islocal
7951 if g:netrw_keepdir
7952 let fname= s:ComposePath(curdir,fname)
7953 endif
7954 else
7955 let fname= curdir.fname
7956 endif
7957 1split
7958 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007961" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 hardcopy
7963 q
7964 endfor
7965 2match none
7966 endif
7967" call Dret("s:NetrwMarkFilePrint")
7968endfun
7969
7970" ---------------------------------------------------------------------
7971" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7972" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007973" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007974fun! s:NetrwMarkFileRegexp(islocal)
7975" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7976
7977 " get the regular expression
7978 call inputsave()
7979 let regexp= input("Enter regexp: ","","file")
7980 call inputrestore()
7981
7982 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007984" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007987 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007988 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 else
7991 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007992 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007994" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995
7996 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007997 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007998 if fname =~ '^'.fnameescape(curdir)
7999" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8001 else
8002" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8003 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8004 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008005 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008008" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009
8010 " convert displayed listing into a filelist
8011 let eikeep = &ei
8012 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008013 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008014 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008018 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 sil NetrwKeepj norm! "ap
8020 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008023 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008029 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008031 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8032 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008033 call histdel("/",-1)
8034 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 endif
8036 " convert regexp into the more usual glob-style format
8037 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008038" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008040 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 let filelist= getline(1,line("$"))
8042 q!
8043 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 endfor
8046 unlet filelist
8047 let @a = areg
8048 let &ei = eikeep
8049 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008050 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051
8052" call Dret("s:NetrwMarkFileRegexp")
8053endfun
8054
8055" ---------------------------------------------------------------------
8056" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8057" Uses the local marked file list.
8058fun! s:NetrwMarkFileSource(islocal)
8059" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8060 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008061
8062 " sanity check
8063 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008065" call Dret("s:NetrwMarkFileSource")
8066 return
8067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8069 let curdir= s:NetrwGetCurdir(a:islocal)
8070
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 if exists("s:netrwmarkfilelist_{curbufnr}")
8072 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 call s:NetrwUnmarkList(curbufnr,curdir)
8074 for fname in netrwmarkfilelist
8075 if a:islocal
8076 if g:netrw_keepdir
8077 let fname= s:ComposePath(curdir,fname)
8078 endif
8079 else
8080 let fname= curdir.fname
8081 endif
8082 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008084 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085 endfor
8086 2match none
8087 endif
8088" call Dret("s:NetrwMarkFileSource")
8089endfun
8090
8091" ---------------------------------------------------------------------
8092" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8093" Uses the global markfilelist
8094fun! s:NetrwMarkFileTag(islocal)
8095" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008096 let svpos = winsaveview()
8097" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008099 let curbufnr = bufnr("%")
8100
Bram Moolenaarff034192013-04-24 18:51:19 +02008101 " sanity check
8102 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008103 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008104" call Dret("s:NetrwMarkFileTag")
8105 return
8106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008108
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8111 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 call s:NetrwUnmarkAll()
8113
8114 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008115
8116" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8117 call system(g:netrw_ctags." ".netrwmarkfilelist)
8118 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8120 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008121
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008123 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008124 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let curdir= b:netrw_curdir
8126 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008129" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008130 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008131 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 wq!
8133 endif
8134 2match none
8135 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008136" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8137 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 endif
8139
8140" call Dret("s:NetrwMarkFileTag")
8141endfun
8142
8143" ---------------------------------------------------------------------
8144" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008145" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008146" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008147" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008148" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008150" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8151 let svpos = winsaveview()
8152" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let hadtgt = exists("s:netrwmftgt")
8155 if !exists("w:netrw_bannercnt")
8156 let w:netrw_bannercnt= b:netrw_bannercnt
8157 endif
8158
8159 " set up target
8160 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8163 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 unlet s:netrwmftgt s:netrwmftgt_islocal
8166 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008167 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008168 endif
8169 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008170" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8171 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008172" call Dret("s:NetrwMarkFileTgt : removed target")
8173 return
8174 else
8175 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008177 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178
8179 else
8180 " get word under cursor.
8181 " * If directory, use it for the target.
8182 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let curword= s:NetrwGetWord()
8185 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 elseif !a:islocal && tgtdir =~ '/$'
8190 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 else
8193 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 endif
8196 endif
8197 if a:islocal
8198 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8199 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 endif
8202 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008204 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8205 endif
8206 let s:netrwmftgt_islocal= a:islocal
8207
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008208 " need to do refresh so that the banner will be updated
8209 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008210 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008211" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008212 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008215 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8217 else
8218 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8219 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008220" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8221 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008223 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
8225
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8227" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8229endfun
8230
8231" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8233fun! s:NetrwGetCurdir(islocal)
8234" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8235
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8239 elseif !exists("b:netrw_curdir")
8240 let b:netrw_curdir= getcwd()
8241" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8242 endif
8243
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" 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 +01008245 if b:netrw_curdir !~ '\<\a\{3,}://'
8246 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008247" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008248 if g:netrw_keepdir == 0
8249 call s:NetrwLcd(curdir)
8250 endif
8251 endif
8252
8253" call Dret("s:NetrwGetCurdir <".curdir.">")
8254 return b:netrw_curdir
8255endfun
8256
8257" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008258" s:NetrwOpenFile: query user for a filename and open it {{{2
8259fun! s:NetrwOpenFile(islocal)
8260" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008261 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008262 call inputsave()
8263 let fname= input("Enter filename: ")
8264 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008265" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8266
8267 " determine if Lexplore is in use
8268 if exists("t:netrw_lexbufnr")
8269 " check if t:netrw_lexbufnr refers to a netrw window
8270" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8271 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8272 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8273" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8274 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8275 exe "NetrwKeepj e ".fnameescape(fname)
8276 let @@= ykeep
8277" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8278 endif
8279 endif
8280
8281 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008282 if fname !~ '[/\\]'
8283 if exists("b:netrw_curdir")
8284 if exists("g:netrw_quiet")
8285 let netrw_quiet_keep = g:netrw_quiet
8286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008287 let g:netrw_quiet = 1
8288 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008289 let s:rexposn_{bufnr("%")}= winsaveview()
8290" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008291 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008293 else
8294 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8295 endif
8296 if exists("netrw_quiet_keep")
8297 let g:netrw_quiet= netrw_quiet_keep
8298 else
8299 unlet g:netrw_quiet
8300 endif
8301 endif
8302 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008303 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008304 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008305 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008306" call Dret("s:NetrwOpenFile")
8307endfun
8308
8309" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008310" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8311" For the mapping to this function be made via
8312" netrwPlugin, you'll need to have had
8313" g:netrw_usetab set to non-zero.
8314fun! netrw#Shrink()
8315" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8316 let curwin = winnr()
8317 let wiwkeep = &wiw
8318 set wiw=1
8319
8320 if &ft == "netrw"
8321 if winwidth(0) > g:netrw_wiw
8322 let t:netrw_winwidth= winwidth(0)
8323 exe "vert resize ".g:netrw_wiw
8324 wincmd l
8325 if winnr() == curwin
8326 wincmd h
8327 endif
8328" call Decho("vert resize 0",'~'.expand("<slnum>"))
8329 else
8330 exe "vert resize ".t:netrw_winwidth
8331" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8332 endif
8333
8334 elseif exists("t:netrw_lexbufnr")
8335 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8336 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8337 let t:netrw_winwidth= winwidth(0)
8338 exe "vert resize ".g:netrw_wiw
8339 wincmd l
8340 if winnr() == curwin
8341 wincmd h
8342 endif
8343" call Decho("vert resize 0",'~'.expand("<slnum>"))
8344 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8345 exe "vert resize ".t:netrw_winwidth
8346" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8347 else
8348 call netrw#Lexplore(0,0)
8349 endif
8350
8351 else
8352 call netrw#Lexplore(0,0)
8353 endif
8354 let wiw= wiwkeep
8355
8356" call Dret("netrw#Shrink")
8357endfun
8358
8359" ---------------------------------------------------------------------
8360" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8361fun! s:NetSortSequence(islocal)
8362" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8363
8364 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008365 let svpos= winsaveview()
8366" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008367 call inputsave()
8368 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8369 call inputrestore()
8370
8371 " refresh the listing
8372 let g:netrw_sort_sequence= newsortseq
8373 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8375 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008376 let @@= ykeep
8377
8378" call Dret("NetSortSequence")
8379endfun
8380
8381" ---------------------------------------------------------------------
8382" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8383" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008384" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385fun! s:NetrwUnmarkList(curbufnr,curdir)
8386" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8387
8388 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8391 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8392 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8393 call remove(s:netrwmarkfilelist,idx) " remove from global list
8394 endfor
8395 if s:netrwmarkfilelist == []
8396 unlet s:netrwmarkfilelist
8397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008398
Bram Moolenaar446cb832008-06-24 21:56:24 +00008399 " getting rid of the local marked-file lists is easy
8400 unlet s:netrwmarkfilelist_{a:curbufnr}
8401 endif
8402 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8403 unlet s:netrwmarkfilemtch_{a:curbufnr}
8404 endif
8405 2match none
8406" call Dret("s:NetrwUnmarkList")
8407endfun
8408
8409" ---------------------------------------------------------------------
8410" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8411fun! s:NetrwUnmarkAll()
8412" call Dfunc("s:NetrwUnmarkAll()")
8413 if exists("s:netrwmarkfilelist")
8414 unlet s:netrwmarkfilelist
8415 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008416 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 2match none
8418" call Dret("s:NetrwUnmarkAll")
8419endfun
8420
8421" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008422" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423fun! s:NetrwUnmarkAll2()
8424" call Dfunc("s:NetrwUnmarkAll2()")
8425 redir => netrwmarkfilelist_let
8426 let
8427 redir END
8428 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8431 for flist in netrwmarkfilelist_list
8432 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8433 unlet s:netrwmarkfilelist_{curbufnr}
8434 unlet s:netrwmarkfilemtch_{curbufnr}
8435 endfor
8436" call Dret("s:NetrwUnmarkAll2")
8437endfun
8438
8439" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008440" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8441"
8442" Marked files are in two types of lists:
8443" s:netrwmarkfilelist -- holds complete paths to all marked files
8444" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8445"
8446" Marked files suitable for use with 2match are in:
8447" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448fun! s:NetrwUnMarkFile(islocal)
8449" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008450 let svpos = winsaveview()
8451" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 let curbufnr = bufnr("%")
8453
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454 " unmark marked file list
8455 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8456 if exists("s:netrwmarkfilelist")
8457" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 endif
8460
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461 let ibuf= 1
8462 while ibuf < bufnr("$")
8463 if exists("s:netrwmarkfilelist_".ibuf)
8464 unlet s:netrwmarkfilelist_{ibuf}
8465 unlet s:netrwmarkfilemtch_{ibuf}
8466 endif
8467 let ibuf = ibuf + 1
8468 endwhile
8469 2match none
8470
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008472"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8473call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008474" call Dret("s:NetrwUnMarkFile")
8475endfun
8476
8477" ---------------------------------------------------------------------
8478" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8479fun! s:NetrwMenu(domenu)
8480
8481 if !exists("g:NetrwMenuPriority")
8482 let g:NetrwMenuPriority= 80
8483 endif
8484
Bram Moolenaaradc21822011-04-01 18:03:16 +02008485 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8487
8488 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008491 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8495 if g:netrw_dirhistmax > 0
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8500 else
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8502 endif
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8517 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 +01008518 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 +02008519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8548 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>'
8549 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>'
8550 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>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8552 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>'
8553 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>'
8554 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 +01008555 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 +02008556 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008559 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8560 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561
8562 elseif !a:domenu
8563 let s:netrwcnt = 0
8564 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008565 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 exe curwin."wincmd w"
8567
8568 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008569" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008570 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008571" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008572 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 endif
8574 endif
8575" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008576 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 endif
8578
8579endfun
8580
8581" ---------------------------------------------------------------------
8582" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8583" Used by the O maps (as <SID>NetrwObtain())
8584fun! s:NetrwObtain(islocal)
8585" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8586
Bram Moolenaar97d62492012-11-15 21:28:22 +01008587 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008589 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008590 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8592 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008593 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008595 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596
8597" call Dret("NetrwObtain")
8598endfun
8599
8600" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8602" If there's only one window, then the window will first be split.
8603" Returns:
8604" choice = 0 : didn't have to choose
8605" choice = 1 : saved modified file in window first
8606" choice = 2 : didn't save modified file, opened window
8607" choice = 3 : cancel open
8608fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008609" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610
Bram Moolenaar97d62492012-11-15 21:28:22 +01008611 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008613 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615
8616 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008617 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8620" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8621 let curword = s:NetrwGetWord()
8622 let choice = 0
8623 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8624" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008625 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008626" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008627 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008628" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 if lastwinnr == 1
8634 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" 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 +02008636 " g:netrw_preview=0: preview window shown in a horizontally split window
8637 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008639 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008640 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008642 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008644 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008645 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008647 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008649 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651
8652 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008653" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008658 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#12: mod=".&mod)
8664
8665 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8666 " whoops -- user trying to open file in the Lexplore window.
8667 " Use Lexplore's opening-file window instead.
8668" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8669" exe g:netrw_chgwin."wincmd w"
8670 wincmd p
8671 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8672 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008673
8674 " prevwinnr: the window number of the "prev" window
8675 " prevbufnr: the buffer number of the buffer in the "prev" window
8676 " bnrcnt : the qty of windows open on the "prev" buffer
8677 let prevwinnr = winnr()
8678 let prevbufnr = bufnr("%")
8679 let prevbufname = bufname("%")
8680 let prevmod = &mod
8681 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008683 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008684" 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 +01008685" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686
8687 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008688 " and it doesn't appear in any other extant window, then ask the
8689 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008692 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008693" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008695" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696
8697 if bnrcnt == 1 && &hidden == 0
8698 " only one copy of the modified buffer in a window, and
8699 " hidden not set, so overwriting will lose the modified file. Ask first...
8700 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008701" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008703" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704
8705 if choice == 1
8706 " Yes -- write file & then browse
8707 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008708 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008710 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008711 exe origwin."wincmd w"
8712 let &ei = eikeep
8713 let @@ = ykeep
8714" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 return choice
8716 endif
8717
8718 elseif choice == 2
8719 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722
8723 else
8724 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008725" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008726 exe origwin."wincmd w"
8727 let &ei= eikeep
8728 let @@ = ykeep
8729" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 return choice
8731 endif
8732 endif
8733 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008734 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008736" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737
8738 " restore b:netrw_curdir (window split/enew may have lost it)
8739 let b:netrw_curdir= curdir
8740 if a:islocal < 2
8741 if a:islocal
8742 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8743 else
8744 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8745 endif
8746 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008747 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749 return choice
8750endfun
8751
8752" ---------------------------------------------------------------------
8753" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8754" Always assumed to be local -> remote
8755" call s:NetrwUpload(filename, target)
8756" call s:NetrwUpload(filename, target, fromdirectory)
8757fun! s:NetrwUpload(fname,tgt,...)
8758" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8759
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760 if a:tgt =~ '^\a\{3,}://'
8761 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 else
8763 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8764 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766
8767 if a:0 > 0
8768 let fromdir= a:1
8769 else
8770 let fromdir= getcwd()
8771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773
8774 if type(a:fname) == 1
8775 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8779 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8780" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 if a:tgt =~ '/$'
8782 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008784 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008787 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 endif
8790 q!
8791
8792 elseif type(a:fname) == 3
8793 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 let curdir= getcwd()
8796 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008797 if s:NetrwLcd(fromdir)
8798" call Dret("s:NetrwUpload : lcd failure")
8799 return
8800 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008801 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803 if exists("g:netrw_port") && g:netrw_port != ""
8804 let useport= " ".g:netrw_scpport." ".g:netrw_port
8805 else
8806 let useport= ""
8807 endif
8808 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8809 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810 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 +02008811 if s:NetrwLcd(curdir)
8812" call Dret("s:NetrwUpload : lcd failure")
8813 return
8814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815
8816 elseif a:tgt =~ '^ftp:'
8817 call s:NetrwMethod(a:tgt)
8818
8819 if b:netrw_method == 2
8820 " handle uploading a list of files via ftp+.netrc
8821 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008826" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827
8828 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
8832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835
Bram Moolenaaradc21822011-04-01 18:03:16 +02008836 if tgtdir == ""
8837 let tgtdir= '/'
8838 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841
8842 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8844" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 endfor
8846
8847 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008848 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 +00008849 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8851 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 endif
8853 " 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 +01008854 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008855 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8857 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8858 else
8859 bw!|q
8860 endif
8861
8862 elseif b:netrw_method == 3
8863 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8864 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008867 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008873 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008874" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875 endif
8876
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008877 if exists("g:netrw_uid") && g:netrw_uid != ""
8878 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008881 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008882 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889 endif
8890
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893
8894 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008896" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 endif
8898
8899 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
8904 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008906" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 endfor
8908
8909 " perform ftp:
8910 " -i : turns off interactive prompting from ftp
8911 " -n unix : DON'T use <.netrc>, even though it exists
8912 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008913 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008914 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 " 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 +01008916 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008917 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8919 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008920 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8922 let &debug = debugkeep
8923 let mod = 1
8924 else
8925 bw!|q
8926 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008927 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008929 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 endif
8931 else
8932 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8933 endif
8934 endif
8935
8936" call Dret("s:NetrwUpload")
8937endfun
8938
8939" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941fun! s:NetrwPreview(path) range
8942" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8944" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008945 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946 NetrwKeepj call s:NetrwOptionsSave("s:")
8947 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8948 NetrwKeepj call s:NetrwOptionsSafe(1)
8949 else
8950 NetrwKeepj call s:NetrwOptionsSafe(0)
8951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008954 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8956 if g:netrw_preview
8957 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008958 let pvhkeep = &pvh
8959 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8960 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8962 else
8963 " horizontal split
8964 let pvhkeep = &pvh
8965 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8966 let &pvh = winheight(0) - winsz
8967" 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 +02008968 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969 " g:netrw_preview g:netrw_alto
8970 " 1 : vert 1: top -- preview window is vertically split off and on the left
8971 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8972 " 0 : 1: top -- preview window is horizontally split off and on the top
8973 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8974 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008975 " 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 +02008976 " the BufEnter event set up in netrwPlugin.vim
8977" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8978 let eikeep = &ei
8979 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008981 let &ei= eikeep
8982" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008983 if exists("pvhkeep")
8984 let &pvh= pvhkeep
8985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988 endif
8989 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008990 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 +00008991 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008992 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008993 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994" call Dret("NetrwPreview")
8995endfun
8996
8997" ---------------------------------------------------------------------
8998" s:NetrwRefresh: {{{2
8999fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009000" 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 +00009001 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009002 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003" call Decho("setl ma noro",'~'.expand("<slnum>"))
9004" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009005 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009006 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9007 if !exists("w:netrw_treetop")
9008 if exists("b:netrw_curdir")
9009 let w:netrw_treetop= b:netrw_curdir
9010 else
9011 let w:netrw_treetop= getcwd()
9012 endif
9013 endif
9014 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9015 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009016
9017 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009018 let screenposn = winsaveview()
9019" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009020
9021" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9022" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9023 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009024 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009026 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009029
9030 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009031" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9032 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033
9034 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009035 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9036 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9037" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9038 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9039 else
9040" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9041 2match none
9042 endif
9043 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044
Bram Moolenaar97d62492012-11-15 21:28:22 +01009045" restore
9046 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009047" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048endfun
9049
9050" ---------------------------------------------------------------------
9051" s:NetrwRefreshDir: refreshes a directory by name {{{2
9052" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009053" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009055" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 if g:netrw_fastbrowse == 0
9057 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009058" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061
9062 if tgtwin > 0
9063 " tgtwin is being displayed, so refresh it
9064 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009067 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009068 exe curwin."wincmd w"
9069
9070 elseif bufnr(a:dirname) > 0
9071 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9073 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 endif
9075
9076 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009078 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 endif
9080" call Dret("s:NetrwRefreshDir")
9081endfun
9082
9083" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009084" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9085" window number to do its editing in.
9086" Supports [count]C where the count, if present, is used to specify
9087" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009089" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009090 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 if a:1 == "" " :NetrwC win#
9093 let g:netrw_chgwin= winnr()
9094 else " :NetrwC
9095 let g:netrw_chgwin= a:1
9096 endif
9097 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009098 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009100 let g:netrw_chgwin= winnr()
9101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009104endfun
9105
9106" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009107" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9108" What this function does is to compute a priority for the patterns
9109" in the g:netrw_sort_sequence. It applies a substitute to any
9110" "files" that satisfy each pattern, putting the priority / in
9111" front. An "*" pattern handles the default priority.
9112fun! s:NetrwSetSort()
9113" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009114 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 if w:netrw_liststyle == s:LONGLIST
9116 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9117 else
9118 let seqlist = g:netrw_sort_sequence
9119 endif
9120 " sanity check -- insure that * appears somewhere
9121 if seqlist == ""
9122 let seqlist= '*'
9123 elseif seqlist !~ '\*'
9124 let seqlist= seqlist.',*'
9125 endif
9126 let priority = 1
9127 while seqlist != ""
9128 if seqlist =~ ','
9129 let seq = substitute(seqlist,',.*$','','e')
9130 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9131 else
9132 let seq = seqlist
9133 let seqlist = ""
9134 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009135 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009136 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009138 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009139 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009140 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009142" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143
9144 " sanity check
9145 if w:netrw_bannercnt > line("$")
9146 " apparently no files were left after a Hiding pattern was used
9147" call Dret("SetSort : no files left after hiding")
9148 return
9149 endif
9150 if seq == '*'
9151 let starpriority= spriority
9152 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009153 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009154 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155 " sometimes multiple sorting patterns will match the same file or directory.
9156 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9158 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159 endif
9160 let priority = priority + 1
9161 endwhile
9162 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9164 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 endif
9166
9167 " Following line associated with priority -- items that satisfy a priority
9168 " pattern get prefixed by ###/ which permits easy sorting by priority.
9169 " Sometimes files can satisfy multiple priority patterns -- only the latest
9170 " priority pattern needs to be retained. So, at this point, these excess
9171 " priority prefixes need to be removed, but not directories that happen to
9172 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009173 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9174 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009175 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176
9177" call Dret("SetSort")
9178endfun
9179
Bram Moolenaarff034192013-04-24 18:51:19 +02009180" ---------------------------------------------------------------------
9181" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9182" Implements [count]Tb (bookhist<b>)
9183" [count]Th (bookhist<h>)
9184" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009185fun! s:NetrwSetTgt(islocal,bookhist,choice)
9186" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009187
9188 if a:bookhist == 'b'
9189 " supports choosing a bookmark as a target using a qb-generated list
9190 let choice= a:choice - 1
9191 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009192 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009193 else
9194 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9195 endif
9196
9197 elseif a:bookhist == 'h'
9198 " supports choosing a history stack entry as a target using a qb-generated list
9199 let choice= (a:choice % g:netrw_dirhistmax) + 1
9200 if exists("g:netrw_dirhist_".choice)
9201 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009202 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009203 else
9204 echomsg "Sorry, history#".a:choice." not available!"
9205 endif
9206 endif
9207
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009208 " refresh the display
9209 if !exists("b:netrw_curdir")
9210 let b:netrw_curdir= getcwd()
9211 endif
9212 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9213
Bram Moolenaarff034192013-04-24 18:51:19 +02009214" call Dret("s:NetrwSetTgt")
9215endfun
9216
Bram Moolenaar446cb832008-06-24 21:56:24 +00009217" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009218" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009219fun! s:NetrwSortStyle(islocal)
9220" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009221 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009222 let svpos= winsaveview()
9223" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009225 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 +01009226 NetrwKeepj norm! 0
9227 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009228" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9229 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230
9231" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9232endfun
9233
9234" ---------------------------------------------------------------------
9235" s:NetrwSplit: mode {{{2
9236" =0 : net and o
9237" =1 : net and t
9238" =2 : net and v
9239" =3 : local and o
9240" =4 : local and t
9241" =5 : local and v
9242fun! s:NetrwSplit(mode)
9243" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9244
Bram Moolenaar97d62492012-11-15 21:28:22 +01009245 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 call s:SaveWinVars()
9247
9248 if a:mode == 0
9249 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009250 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009251 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009252" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009253 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj call s:RestoreWinVars()
9256 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257 unlet s:didsplit
9258
9259 elseif a:mode == 1
9260 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009261 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 tabnew
9264 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj call s:RestoreWinVars()
9266 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 unlet s:didsplit
9268
9269 elseif a:mode == 2
9270 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009271 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009272 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009274 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 3
9281 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009282 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009283 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009285 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj call s:RestoreWinVars()
9288 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289 unlet s:didsplit
9290
9291 elseif a:mode == 4
9292 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009294 let eikeep = &ei
9295 let netrw_winnr = winnr()
9296 let netrw_line = line(".")
9297 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009299 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009300 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009301 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9302 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009303 let &ei = eikeep
9304 let netrw_curdir = s:NetrwTreeDir(0)
9305" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009307 let b:netrw_curdir = netrw_curdir
9308 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj call s:RestoreWinVars()
9310 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009311 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009312 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009313 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9314 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009315 let &ei= eikeep
9316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317 unlet s:didsplit
9318
9319 elseif a:mode == 5
9320 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009321 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009322 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009323" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009324 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 NetrwKeepj call s:RestoreWinVars()
9327 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 unlet s:didsplit
9329
9330 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 endif
9333
Bram Moolenaar97d62492012-11-15 21:28:22 +01009334 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335" call Dret("s:NetrwSplit")
9336endfun
9337
9338" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009339" s:NetrwTgtMenu: {{{2
9340fun! s:NetrwTgtMenu()
9341 if !exists("s:netrw_menucnt")
9342 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009343 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009344" call Dfunc("s:NetrwTgtMenu()")
9345
9346 " the following test assures that gvim is running, has menus available, and has menus enabled.
9347 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9348 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009349" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009350 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9351 endif
9352 if !exists("s:netrw_initbookhist")
9353 call s:NetrwBookHistRead()
9354 endif
9355
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356 " try to cull duplicate entries
9357 let tgtdict={}
9358
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 " target bookmarked places
9360 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009362 let cnt= 1
9363 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364 if has_key(tgtdict,bmd)
9365 let cnt= cnt + 1
9366 continue
9367 endif
9368 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 let ebmd= escape(bmd,g:netrw_menu_escape)
9370 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009372 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 +02009373 let cnt= cnt + 1
9374 endfor
9375 endif
9376
9377 " target directory browsing history
9378 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 let histcnt = 1
9381 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009382 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009383 if exists("g:netrw_dirhist_{histcnt}")
9384 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 if has_key(tgtdict,histentry)
9386 let histcnt = histcnt + 1
9387 continue
9388 endif
9389 let tgtdict[histentry] = histcnt
9390 let ehistentry = escape(histentry,g:netrw_menu_escape)
9391" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009392 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 +02009393 endif
9394 let histcnt = histcnt + 1
9395 endwhile
9396 endif
9397 endif
9398" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399endfun
9400
9401" ---------------------------------------------------------------------
9402" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9403" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009404fun! s:NetrwTreeDir(islocal)
9405" 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 +02009406" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009407" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9408" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9409" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009410" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009411
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009412 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009413 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414" 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 +01009415 let treedir= s:treedir
9416 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009417 unlet s:prevwinopen
9418" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009419 return treedir
9420 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421 if exists("s:prevwinopen")
9422 unlet s:prevwinopen
9423 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009424" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425
Bram Moolenaar8d043172014-01-23 14:24:41 +01009426 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9427 let b:netrw_curdir= getcwd()
9428 endif
9429 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433 let s:treecurpos= winsaveview()
9434" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009436
9437 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9439" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009440" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009441
9442 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009443 let curline= substitute(getline('.'),"\t -->.*$",'','')
9444 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009447" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9448 elseif curline =~ '@$'
9449" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009450 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 let treedir= ""
9455 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009456" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457
9458 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9460" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009461" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009462 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9466 sil! NetrwKeepj %d _
9467" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009469" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009470" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009471 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009472" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009475" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009476" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009477
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9479" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9480" let newdir = w:netrw_treetop.'/'.potentialdir
9481" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9482" let treedir = s:NetrwTreePath(newdir)
9483" let w:netrw_treetop = newdir
9484" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9485" else
9486" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009487 if a:islocal && curline =~ '@$'
9488 if isdirectory(s:NetrwFile(potentialdir))
9489 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9490 let w:netrw_treetop = treedir
9491 endif
9492 else
9493 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9494 let treedir = s:NetrwTreePath(w:netrw_treetop)
9495 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009496 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009497" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009498
9499 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009502" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009504" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009505 return treedir
9506endfun
9507
9508" ---------------------------------------------------------------------
9509" s:NetrwTreeDisplay: recursive tree display {{{2
9510fun! s:NetrwTreeDisplay(dir,depth)
9511" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9512
9513 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009514 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515
9516 " install ../ and shortdir
9517 if a:depth == ""
9518 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009519" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 if a:dir == w:netrw_treetop
9523 let shortdir= a:dir
9524 else
9525 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9526 endif
9527 call setline(line("$")+1,a:depth.shortdir)
9528 else
9529 let shortdir= substitute(a:dir,'^.*/','','e')
9530 call setline(line("$")+1,a:depth.shortdir.'/')
9531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 " append a / to dir if its missing one
9534 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535
9536 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009537 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539
Bram Moolenaar85850f32019-07-19 22:05:51 +02009540 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9541 if g:netrw_hide == 1
9542 " hide given patterns
9543 let listhide= split(g:netrw_list_hide,',')
9544" call Decho("listhide=".string(listhide))
9545 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009546 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009547 endfor
9548
9549 elseif g:netrw_hide == 2
9550 " show given patterns (only)
9551 let listhide= split(g:netrw_list_hide,',')
9552" call Decho("listhide=".string(listhide))
9553 let entries=[]
9554 for entry in w:netrw_treedict[dir]
9555 for pat in listhide
9556 if entry =~ pat
9557 call add(entries,entry)
9558 break
9559 endif
9560 endfor
9561 endfor
9562 let w:netrw_treedict[dir]= entries
9563 endif
9564 if depth != ""
9565 " always remove "." and ".." entries when there's depth
9566 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9567 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9568 endif
9569
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009570" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009572 if dir =~ '/$'
9573 let direntry= substitute(dir.entry,'[@/]$','','e')
9574 else
9575 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009580 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9584 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9585" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009589 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 endif
9591 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009592" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009593
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594" call Dret("NetrwTreeDisplay")
9595endfun
9596
9597" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009598" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9599fun! s:NetrwRefreshTreeDict(dir)
9600" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009601 if !exists("w:netrw_treedict")
9602" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9603 return
9604 endif
9605
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 for entry in w:netrw_treedict[a:dir]
9607 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9608" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9609
9610 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9611" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9612 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009613 let liststar = s:NetrwGlob(direntry,'*',1)
9614 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009615 let w:netrw_treedict[direntry] = liststar + listdotstar
9616" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9617
9618 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9619" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9620 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009621 let liststar = s:NetrwGlob(direntry.'/','*',1)
9622 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009623 let w:netrw_treedict[direntry]= liststar + listdotstar
9624" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9625
9626 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9627" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9628 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009629 let liststar = s:NetrwGlob(direntry.'/','*',1)
9630 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009631" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9632
9633 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009634" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635 endif
9636 endfor
9637" call Dret("s:NetrwRefreshTreeDict")
9638endfun
9639
9640" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009642" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009643fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009645" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009646" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9647" 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>"))
9648" 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 +00009649
9650 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009652" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009654 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 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 +02009657" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009662 if exists("w:netrw_treetop")
9663 let s:netrw_treetop= w:netrw_treetop
9664 else
9665 let w:netrw_treetop= getcwd()
9666 let s:netrw_treetop= w:netrw_treetop
9667 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009670 " insure that we have a treedict, albeit empty
9671" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 let w:netrw_treedict= {}
9673 endif
9674
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 " update the dictionary for the current directory
9676" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009681 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682
9683 " if past banner, record word
9684 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9685 let fname= expand("<cword>")
9686 else
9687 let fname= ""
9688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9690" 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 +00009691
9692 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009693" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009696
9697 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9698 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009700 1d
9701 endwhile
9702
Bram Moolenaar13600302014-05-22 18:26:40 +02009703 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009705" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009706 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707 endif
9708endfun
9709
9710" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009711" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009712" Normally, treetop is w:netrw_treetop, but a
9713" user of the function ( netrw#SetTreetop() )
9714" wipes that out prior to calling this function
9715fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009716" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9717 if line(".") < w:netrw_bannercnt + 2
9718 let treedir= a:treetop
9719 if treedir !~ '/$'
9720 let treedir= treedir.'/'
9721 endif
9722" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9723 return treedir
9724 endif
9725
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009726 let svpos = winsaveview()
9727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009728 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009730 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9732 let curline= getline('.')
9733" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9734 if curline =~ '/$'
9735" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9736 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9737" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9738 elseif curline =~ '@\s\+-->'
9739" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9740 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9741 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9742" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 let treedir= ""
9746 endif
9747 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9749" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9751 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9752 let treedir= dirname.treedir
9753 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009756" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 if a:treetop =~ '/$'
9758 let treedir= a:treetop.treedir
9759 else
9760 let treedir= a:treetop.'/'.treedir
9761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009762" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009764" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009765" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9766 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009767" call Dret("s:NetrwTreePath <".treedir.">")
9768 return treedir
9769endfun
9770
9771" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772" s:NetrwWideListing: {{{2
9773fun! s:NetrwWideListing()
9774
9775 if w:netrw_liststyle == s:WIDELIST
9776" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9777 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009778 " cpf: characters per filename
9779 " fpl: filenames per line
9780 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009781 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009782 let dict={}
9783 " save the unnamed register and register 0-9 and a
9784 let dict.a=[getreg('a'), getregtype('a')]
9785 for i in range(0, 9)
9786 let dict[i] = [getreg(i), getregtype(i)]
9787 endfor
9788 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009789" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790 let b:netrw_cpf= 0
9791 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009792 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009793 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9794 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009796 " restore stored registers
9797 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798" call Dret("NetrwWideListing")
9799 return
9800 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009801 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009802 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804
9805 " determine qty files per line (fpl)
9806 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9807 if w:netrw_fpl <= 0
9808 let w:netrw_fpl= 1
9809 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811
9812 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813 " fpc: files per column of wide listing
9814 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009815 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9817 let newcolstart = w:netrw_bannercnt + fpc
9818 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009820 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009821" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009822 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009823 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825 while line("$") >= newcolstart
9826 if newcolend > line("$") | let newcolend= line("$") | endif
9827 let newcolqty= newcolend - newcolstart
9828 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009829 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009831 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009833 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009835 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009836 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009838 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009839" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009840 if @* != keepregstar | sil! let @* = keepregstar | endif
9841 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009842 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009843 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9844 NetrwKeepj call histdel("/",-1)
9845 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9846 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009847" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009848 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009849 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009850" 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 +00009851" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009852 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009853 else
9854 if hasmapto("w","n")
9855 sil! nunmap <buffer> w
9856 endif
9857 if hasmapto("b","n")
9858 sil! nunmap <buffer> b
9859 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861endfun
9862
9863" ---------------------------------------------------------------------
9864" s:PerformListing: {{{2
9865fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009866" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9867" 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 +02009868" 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>"))
9869 sil! NetrwKeepj %d _
9870" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871
Bram Moolenaar15146672011-10-20 22:22:38 +02009872 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009875
Bram Moolenaar85850f32019-07-19 22:05:51 +02009876 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009877 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879
9880" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009881" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882" endif " Decho
9883
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9886 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9888 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889 endif
9890
9891 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009892 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893
9894 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009895 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009897 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898 if exists("g:netrw_pchk")
9899 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9900 " failure detections.
9901 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9904 endif
9905 if exists("g:netrw_pchk")
9906 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9907 else
9908 let curdir= b:netrw_curdir
9909 endif
9910 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9911 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9912 else
9913 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009914 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009915 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009916 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009917 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009920 let w:netrw_bannercnt= 1
9921 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9923" 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 +00009924
Bram Moolenaar85850f32019-07-19 22:05:51 +02009925 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009927 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009928 let sortby= sortby." reversed"
9929 endif
9930
9931 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009932 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009934 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009936 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 NetrwKeepj put ='\" Sorted by '.sortby
9938 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009939 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009942 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9945 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009947" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" 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 +00009949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950
Bram Moolenaar85850f32019-07-19 22:05:51 +02009951 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009952 if g:netrw_banner
9953 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009957 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009958 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009960 endif
9961 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009962 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009965 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967
9968 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009970" 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 +01009971 if g:netrw_list_hide != "" && g:netrw_hide
9972 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009973 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009974 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 endif
9977 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009980
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" 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 +01009982 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" 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 +01009986 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009988" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" 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 +00009990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991
9992 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009993 if g:netrw_banner
9994 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" 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 +01009997" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" 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 +01009999 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010004 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010007 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" 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 +010010009" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10010 return
10011 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
10014 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010015 if !exists("w:netrw_bannercnt")
10016 let w:netrw_bannercnt= 0
10017 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10019" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10020" 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 +010010021
Bram Moolenaar5c736222010-01-06 20:54:52 +010010022 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010023" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010024" 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 +000010025 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010026 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010028 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010031 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010033" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035
Bram Moolenaar5c736222010-01-06 20:54:52 +010010036 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010038 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010039 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 else
10042 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 endif
10045 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010046
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10050 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010052 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010053 " exten: sort by extension
10054 " The histdel(...,-1) calls remove the last search from the search history
10055" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10057 NetrwKeepj call histdel("/",-1)
10058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10059 NetrwKeepj call histdel("/",-1)
10060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10061 NetrwKeepj call histdel("/",-1)
10062 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10063" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010064 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065 " normal direction sorting
10066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10067 else
10068 " reverse direction sorting
10069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10070 endif
10071 endif
10072 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10073 NetrwKeepj call histdel("/",-1)
10074
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010076 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010078 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010084 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010085" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010086 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10087 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010088 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010089 endif
10090
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010091 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010093 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010094 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010095 call histdel("/",-1)
10096 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010097 endif
10098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" 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 +000010100
10101 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10103" 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 +010010104 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" 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 +010010106 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" 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 +000010108
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010110 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010112 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 endif
10114
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010116 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10118 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10121 else
10122" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10123" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10124" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10125" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126 endif
10127
10128 " record previous current directory
10129 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131
10132 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10134" 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 +010010135 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" 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 +020010137 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" 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 +000010139
10140 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010142 exe "setl ".g:netrw_bufsettings
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#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010144 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010146 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10147 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010148" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010149" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010150
Bram Moolenaar8d043172014-01-23 14:24:41 +010010151 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10153" 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 +010010154" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10155 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156 unlet s:treecurpos
10157 endif
10158
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" 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>"))
10160" 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 +000010161" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10162endfun
10163
10164" ---------------------------------------------------------------------
10165" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010166fun! s:SetupNetrwStatusLine(statline)
10167" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10168
10169 if !exists("s:netrw_setup_statline")
10170 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010171" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010172
10173 if !exists("s:netrw_users_stl")
10174 let s:netrw_users_stl= &stl
10175 endif
10176 if !exists("s:netrw_users_ls")
10177 let s:netrw_users_ls= &laststatus
10178 endif
10179
10180 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010181 let dict={}
10182 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010183 redir @a
10184 try
10185 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187 if &bg == "dark"
10188 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10189 else
10190 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10191 endif
10192 endtry
10193 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010194 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010195 endif
10196
10197 " set up status line (may use User9 highlighting)
10198 " insure that windows have a statusline
10199 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010200 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010201 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010202" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010204
10205" call Dret("SetupNetrwStatusLine : stl=".&stl)
10206endfun
10207
Bram Moolenaar85850f32019-07-19 22:05:51 +020010208" =========================================
10209" Remote Directory Browsing Support: {{{1
10210" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010211
10212" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010213" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10214" This function assumes that a long listing will be received. Size, time,
10215" and reverse sorts will be requested of the server but not otherwise
10216" enforced here.
10217fun! s:NetrwRemoteFtpCmd(path,listcmd)
10218" 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 +010010219" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010220 " sanity check: {{{3
10221 if !exists("w:netrw_method")
10222 if exists("b:netrw_method")
10223 let w:netrw_method= b:netrw_method
10224 else
10225 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10226" call Dret("NetrwRemoteFtpCmd")
10227 return
10228 endif
10229 endif
10230
10231 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10232 let ffkeep= &ff
10233 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010234" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010235
10236 " clear off any older non-banner lines " {{{3
10237 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010238" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10239 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010240
10241 ".........................................
10242 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10243 " ftp + <.netrc>: Method #2
10244 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010246 endif
10247 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010248 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010251 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010252" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" 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>"))
10255 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 +010010256 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10258 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 +010010259 endif
10260
10261 ".........................................
10262 elseif w:netrw_method == 3 " {{{3
10263 " ftp + machine,id,passwd,filename: Method #3
10264 setl ff=unix
10265 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010266 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 endif
10270
10271 " handle userid and password
10272 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010273" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10275 call NetUserPass("ftp:".host)
10276 endif
10277 if exists("g:netrw_uid") && g:netrw_uid != ""
10278 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
10283 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 endif
10286 endif
10287
10288 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
10291 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010293" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010296
10297 " perform ftp:
10298 " -i : turns off interactive prompting from ftp
10299 " -n unix : DON'T use <.netrc>, even though it exists
10300 " -n win32: quit being obnoxious about password
10301 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010302" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010304" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010305" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10306" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 endif
10308
10309 ".........................................
10310 elseif w:netrw_method == 9 " {{{3
10311 " sftp username@machine: Method #9
10312 " s:netrw_sftp_cmd
10313 setl ff=unix
10314
10315 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010316 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010317" call Dret("NetrwRemoteFtpCmd")
10318 return
10319
10320 ".........................................
10321 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010322 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010323 endif
10324
10325 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010326 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010327 sil! NetrwKeepj %s/\r$//e
10328 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
10330 if a:listcmd == "dir"
10331 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10333 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10334 NetrwKeepj call histdel("/",-1)
10335 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010336 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 +010010337 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10338 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 endif
10340 endif
10341
10342 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10343 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010344 exe 'NetrwKeepj '.w:netrw_bannercnt
10345 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 endif
10347 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010348 exe 'NetrwKeepj '.w:netrw_bannercnt
10349 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 endif
10351
10352 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010353 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010354" call Dret("NetrwRemoteFtpCmd")
10355endfun
10356
10357" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358" s:NetrwRemoteListing: {{{2
10359fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010360" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010361
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10363 let w:netrw_bannercnt= s:bannercnt
10364 endif
10365 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010366 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010367 endif
10368
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010370
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371 " sanity check:
10372 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010373" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010375" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 if !exists("g:netrw_quiet")
10377 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10378 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010379 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010380" call Dret("s:NetrwRemoteListing -1")
10381 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010382 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383
Bram Moolenaar8d043172014-01-23 14:24:41 +010010384 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010387 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010388 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 +000010389 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010390 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 +000010391 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010392 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010393
Bram Moolenaar85850f32019-07-19 22:05:51 +020010394 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010395" call Dret("s:NetrwRemoteListing -1")
10396 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 let w:netrw_method= b:netrw_method
10403 endif
10404
Bram Moolenaar13600302014-05-22 18:26:40 +020010405 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010406 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010407" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010408 let s:method = "ftp"
10409 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010410 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010412 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 let listcmd= g:netrw_ftp_sizelist_cmd
10414 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418
Bram Moolenaara6878372014-03-22 21:02:50 +010010419 " report on missing file or directory messages
10420 if search('[Nn]o such file or directory\|Failed to change directory')
10421 let mesg= getline(".")
10422 if exists("w:netrw_bannercnt")
10423 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010424 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 setl noma
10426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010427 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010428 call netrw#ErrorMsg(s:WARNING,mesg,96)
10429" call Dret("s:NetrwRemoteListing : -1")
10430 return -1
10431 endif
10432
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010433 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 +000010434 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010435" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437
10438 " cleanup
10439 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10441 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 sil! NetrwKeepj %s/\r$//e
10444 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010446 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010449 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010452" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 exe "sil! NetrwKeepj ".line1
10456 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10462 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10466 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10467 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10468 NetrwKeepj call histdel("/",-1)
10469 NetrwKeepj call histdel("/",-1)
10470 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471 endif
10472 endif
10473
Bram Moolenaar13600302014-05-22 18:26:40 +020010474 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10481 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010483 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10484 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10485 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10486 NetrwKeepj call histdel("/",-1)
10487 NetrwKeepj call histdel("/",-1)
10488 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010490 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10491 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492 endif
10493 else
10494 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10499 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10500" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 endif
10502 endif
10503
10504 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010505 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010507 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10508 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 endif
10510 endif
10511
10512 if w:netrw_liststyle == s:LONGLIST
10513 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010514" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515
10516 if s:method == "ftp"
10517 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010518 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010519 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010522 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 sil! NetrwKeepj 1
10525 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526 let line2= line(".")
10527 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 endif
10531 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010532 exe "sil! NetrwKeepj ".line1
10533 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 endif
10535
10536 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 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 +000010539 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010540" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010541 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010542 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10544 NetrwKeepj call histdel("/",-1)
10545 NetrwKeepj call histdel("/",-1)
10546 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547 endif
10548 endif
10549
10550" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010553
10554" call Dret("s:NetrwRemoteListing 0")
10555 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010556endfun
10557
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558" ---------------------------------------------------------------------
10559" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10560fun! s:NetrwRemoteRm(usrhost,path) range
10561" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010563 let svpos= winsaveview()
10564" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565
10566 let all= 0
10567 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10568 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010569" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 for fname in s:netrwmarkfilelist_{bufnr("%")}
10571 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010572 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010574 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 let all= 1
10576 endif
10577 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010578 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
10580 else
10581 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583
10584 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585 let keepsol = &l:sol
10586 setl nosol
10587 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588
10589 " remove multiple files and directories
10590 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010591 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010593 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010595 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 let all= 1
10597 endif
10598 let ctr= ctr + 1
10599 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 endif
10602
10603 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010605 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010606" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10607 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608
10609" call Dret("s:NetrwRemoteRm")
10610endfun
10611
10612" ---------------------------------------------------------------------
10613" s:NetrwRemoteRmFile: {{{2
10614fun! s:NetrwRemoteRmFile(path,rmfile,all)
10615" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10616
10617 let all= a:all
10618 let ok = ""
10619
10620 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10621 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 if !all
10624 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010626 call inputsave()
10627 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10628 call inputrestore()
10629 echohl NONE
10630 if ok == ""
10631 let ok="no"
10632 endif
10633 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010634 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 let all= 1
10636 endif
10637 endif
10638
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010639 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" 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 +000010641 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644 if path =~ '^\a\{3,}://'
10645 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010647 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10649 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010654 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 let ok="q"
10656 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010657 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10659" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10660" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 if v:shell_error != 0
10669 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010670 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 +010010671 else
10672 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10673 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010674 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 endif
10679 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010680 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 endif
10683
10684 else
10685 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 if !all
10688 call inputsave()
10689 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10690 call inputrestore()
10691 if ok == ""
10692 let ok="no"
10693 endif
10694 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010695 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 let all= 1
10697 endif
10698 endif
10699
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010700 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010702 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 else
10704 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10706" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010707 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709
10710 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10712 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10713" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010714 let ret= system(netrw_rmf_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 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010718 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 endif
10720 endif
10721 endif
10722
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010723 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010724" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725 endif
10726 endif
10727
10728" call Dret("s:NetrwRemoteRmFile ".ok)
10729 return ok
10730endfun
10731
10732" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733" s:NetrwRemoteRename: rename a remote file or directory {{{2
10734fun! s:NetrwRemoteRename(usrhost,path) range
10735" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10736
10737 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010738 let svpos = winsaveview()
10739" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740 let ctr = a:firstline
10741 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10742
10743 " rename files given by the markfilelist
10744 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10745 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 if exists("subfrom")
10748 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 else
10751 call inputsave()
10752 let newname= input("Moving ".oldname." to : ",oldname)
10753 call inputrestore()
10754 if newname =~ '^s/'
10755 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10756 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10757 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759 endif
10760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010761
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010763 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765 let oldname= s:ShellEscape(a:path.oldname)
10766 let newname= s:ShellEscape(a:path.newname)
10767" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010768 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 endif
10770
10771 endfor
10772 call s:NetrwUnMarkFile(1)
10773
10774 else
10775
10776 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010777 let keepsol= &l:sol
10778 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010779 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010780 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781
10782 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010783" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784
10785 call inputsave()
10786 let newname= input("Moving ".oldname." to : ",oldname)
10787 call inputrestore()
10788
10789 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10790 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10791 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792 let oldname= s:ShellEscape(a:path.oldname)
10793 let newname= s:ShellEscape(a:path.newname)
10794" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010795 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010796 endif
10797
10798 let ctr= ctr + 1
10799 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010800 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010801 endif
10802
10803 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010804 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010805" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10806 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807
10808" call Dret("NetrwRemoteRename")
10809endfun
10810
Bram Moolenaar85850f32019-07-19 22:05:51 +020010811" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812" Local Directory Browsing Support: {{{1
10813" ==========================================
10814
10815" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010816" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010817" Should accept: file://localhost/etc/fstab
10818" file:///etc/fstab
10819" file:///c:/WINDOWS/clock.avi
10820" file:///c|/WINDOWS/clock.avi
10821" file://localhost/c:/WINDOWS/clock.avi
10822" file://localhost/c|/WINDOWS/clock.avi
10823" file://c:/foo.txt
10824" file:///c:/foo.txt
10825" 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 +020010826fun! netrw#FileUrlEdit(fname)
10827" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 let fname = a:fname
10829 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010830" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010834 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010837 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 endif
10840 endif
10841 let fname2396 = netrw#RFC2396(fname)
10842 let fname2396e= fnameescape(fname2396)
10843 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010844 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010845" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10849 endif
10850 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010851
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10853" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010855 exe 'NetrwKeepj keepalt edit '.plainfname
10856 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10857
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" 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 +020010859" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 exe "sil doau BufReadPost ".fname2396e
10861endfun
10862
10863" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010864" netrw#LocalBrowseCheck: {{{2
10865fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010866 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010867 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10868 "
10869 " unfortunate interaction -- split window debugging can't be used here, must use
10870 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10871 " another call to LocalBrowseCheck() when attempts to write
10872 " to the DBG buffer are made.
10873 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 " The &ft == "netrw" test was installed because the BufEnter event
10875 " would hit when re-entering netrw windows, creating unexpected
10876 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010878" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" 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 +010010880 " getting E930: Cannot use :redir inside execute
10881"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010882" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10883" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010884
Bram Moolenaar97d62492012-11-15 21:28:22 +010010885 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886 if isdirectory(s:NetrwFile(a:dirname))
10887" 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 +010010888
Bram Moolenaar97d62492012-11-15 21:28:22 +010010889 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10891" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010892 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010893
Bram Moolenaar446cb832008-06-24 21:56:24 +000010894 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010896 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010897
Bram Moolenaar5c736222010-01-06 20:54:52 +010010898 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010900 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010901 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" 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 +010010904" call Dret("netrw#LocalBrowseCheck")
10905 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010907
Bram Moolenaar85850f32019-07-19 22:05:51 +020010908 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010909 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10910 " AND IF the listing style is not a tree listing
10911 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010913 let ibuf = 1
10914 let buflast = bufnr("$")
10915 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10917 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010918 endif
10919 let ibuf= ibuf + 1
10920 endwhile
10921 endif
10922 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923" 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>"))
10924" 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 +000010925 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010926" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927endfun
10928
10929" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010930" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010931" performed any shell command. The idea is to cause all local-browsing
10932" buffers to be refreshed after a user has executed some shell command,
10933" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010934fun! s:LocalBrowseRefresh()
10935" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10937" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010938
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 " determine which buffers currently reside in a tab
10940 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010941" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942 return
10943 endif
10944 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010945" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 return
10947 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010948 if !empty(getcmdwintype())
10949 " cannot move away from cmdline window, see :h E11
10950 return
10951 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010952 if exists("s:netrw_events") && s:netrw_events == 1
10953 " s:LocalFastBrowser gets called (indirectly) from a
10954 let s:netrw_events= 2
10955" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10956 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 let itab = 1
10959 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010960 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010961 while itab <= tabpagenr("$")
10962 let buftablist = buftablist + tabpagebuflist()
10963 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010964 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10967" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10969 " | refresh any netrw window
10970 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010971 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 let ibl = 0
10973 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10976 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010977 " (ibuf not shown in a current window AND
10978 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10980 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 continue
10984 elseif index(tabpagebuflist(),ibuf) != -1
10985 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010988 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010989 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10990 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10991 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10992 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010994 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10995 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10996 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010997 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 endif
10999 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011001 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011002" call Decho("restore window: win_gotoid(".curwinid.")")
11003 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011004 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005
Bram Moolenaara6878372014-03-22 21:02:50 +010011006" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011007endfun
11008
11009" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011010" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11011"
11012" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11015" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017"
11018" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11019" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011020" (re-using a buffer may not be as accurate)
11021"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011022" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011023" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11024" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11025" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11026" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011028" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11029" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11030" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11031" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032
11033 " initialize browselist, a list of buffer numbers that the local browser has used
11034 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011035" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036 let s:netrw_browselist= []
11037 endif
11038
11039 " append current buffer to fastbrowse list
11040 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011042 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 endif
11045
11046 " enable autocmd events to handle refreshing/removing local browser buffers
11047 " If local browse buffer is currently showing: refresh it
11048 " If local browse buffer is currently hidden : wipe it
11049 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11050 " =1 : medium speed, re-use directory listing for remote only
11051 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011052 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11053 let s:netrw_events= 1
11054 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011056 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011060" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011062 endif
11063 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064
11065 " user must have changed fastbrowse to its fast setting, so remove
11066 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011067 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011069 unlet s:netrw_events
11070 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071 au!
11072 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074 endif
11075
Bram Moolenaar85850f32019-07-19 22:05:51 +020011076" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011077endfun
11078
11079" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011080" s:LocalListing: does the job of "ls" for local directories {{{2
11081fun! s:LocalListing()
11082" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11084" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11085" 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 +010011086
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" 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
11088" 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
11089" 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 +010011090
11091 " get the list of files contained in the current directory
11092 let dirname = b:netrw_curdir
11093 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011094 let filelist = s:NetrwGlob(dirname,"*",0)
11095 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011097
Nir Lichtman1e34b952024-05-08 19:19:34 +020011098 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11101 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011103 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 endif
11106
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011107" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011109" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110
11111 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11112 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11113 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11115" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" 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 +010011118
11119 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120" call Decho(" ",'~'.expand("<slnum>"))
11121" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122
11123 if getftype(filename) == "link"
11124 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 let pfile= filename."@"
11127
11128 elseif getftype(filename) == "socket"
11129 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 let pfile= filename."="
11132
11133 elseif getftype(filename) == "fifo"
11134 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."|"
11137
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011138 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."/"
11142
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011144 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11146 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 let pfile= filename."*"
11149 else
11150 " normal file
11151 let pfile= filename
11152 endif
11153 elseif executable(filename)
11154 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011156 let pfile= filename."*"
11157 else
11158 " normal file
11159 let pfile= filename
11160 endif
11161
11162 else
11163 " normal file
11164 let pfile= filename
11165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011167
11168 if pfile =~ '//$'
11169 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011170" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171 endif
11172 let pfile= strpart(pfile,dirnamelen)
11173 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011174" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11175" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011176
11177 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011178 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11179 let sz = getfsize(filename)
11180 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11181 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011182
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011183 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011184 let sz= s:NetrwHumanReadable(sz)
11185 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011186 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011187 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011188" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 endif
11190
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011191 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011192 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011193 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011194" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011195" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011197 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011198" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011200 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011201
11202 elseif g:netrw_sort_by =~ "^s"
11203 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011207 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011208" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011210 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011211
11212 else
11213 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011214" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011216 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011217 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011218" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 endfor
11220
11221 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011222 sil! NetrwKeepj g/^$/d
11223 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011225" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011226 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11227
11228" call Dret("s:LocalListing")
11229endfun
11230
11231" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011232" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11233fun! s:NetrwLocalExecute(cmd)
11234" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11235 let ykeep= @@
11236 " sanity check
11237 if !executable(a:cmd)
11238 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11239 let @@= ykeep
11240" call Dret("s:NetrwLocalExecute")
11241 return
11242 endif
11243
11244 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011245" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011246 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011247" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011248
11249 " strip any ansi escape sequences off
11250 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11251
11252 " show user the result(s)
11253 echomsg result
11254 let @@= ykeep
11255
11256" call Dret("s:NetrwLocalExecute")
11257endfun
11258
11259" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011260" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261fun! s:NetrwLocalRename(path) range
11262" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11263
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011264 if !exists("w:netrw_bannercnt")
11265 let w:netrw_bannercnt= b:netrw_bannercnt
11266 endif
11267
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011269 let ykeep = @@
11270 let ctr = a:firstline
11271 let svpos = winsaveview()
11272 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011273" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274
11275 " rename files given by the markfilelist
11276 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11277 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011278" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 if exists("subfrom")
11280 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011281" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 else
11283 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011284 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011286 if newname =~ ''
11287 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11288 let newname = substitute(newname,'^.*','','')
11289 elseif newname =~ ''
11290 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11291 let newname = substitute(newname,'[^/]*','','')
11292 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 if newname =~ '^s/'
11294 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11295 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011296" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011297 let newname = substitute(oldname,subfrom,subto,'')
11298 endif
11299 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011300 if !all && filereadable(newname)
11301 call inputsave()
11302 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11303 call inputrestore()
11304 if response == "all"
11305 let all= 1
11306 elseif response != "y" && response != "yes"
11307 " refresh the directory
11308" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11309 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11310" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11311 NetrwKeepj call winrestview(svpos)
11312 let @@= ykeep
11313" call Dret("NetrwLocalRename")
11314 return
11315 endif
11316 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011317 call rename(oldname,newname)
11318 endfor
11319 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011320
Bram Moolenaar97d62492012-11-15 21:28:22 +010011321 else
11322
11323 " attempt to rename files/directories
11324 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011325 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011326
11327 " sanity checks
11328 if line(".") < w:netrw_bannercnt
11329 let ctr= ctr + 1
11330 continue
11331 endif
11332 let curword= s:NetrwGetWord()
11333 if curword == "./" || curword == "../"
11334 let ctr= ctr + 1
11335 continue
11336 endif
11337
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011338 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011339 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011340" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011341
11342 call inputsave()
11343 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11344 call inputrestore()
11345
11346 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011347" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348
11349 let ctr= ctr + 1
11350 endwhile
11351 endif
11352
11353 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011354" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011355 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011356" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11357 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011358 let @@= ykeep
11359
11360" call Dret("NetrwLocalRename")
11361endfun
11362
11363" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364" s:NetrwLocalRm: {{{2
11365fun! s:NetrwLocalRm(path) range
11366" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011367" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011368
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011369 if !exists("w:netrw_bannercnt")
11370 let w:netrw_bannercnt= b:netrw_bannercnt
11371 endif
11372
Bram Moolenaar446cb832008-06-24 21:56:24 +000011373 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011374 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375 let ret = 0
11376 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011377 let svpos = winsaveview()
11378" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379
11380 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11381 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011382" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 for fname in s:netrwmarkfilelist_{bufnr("%")}
11384 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011385 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011387 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011388 let all= 1
11389 endif
11390 endfor
11391 call s:NetrwUnMarkFile(1)
11392
11393 else
11394 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011397 let keepsol= &l:sol
11398 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 let ctr = a:firstline
11400 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011401 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011402
11403 " sanity checks
11404 if line(".") < w:netrw_bannercnt
11405 let ctr= ctr + 1
11406 continue
11407 endif
11408 let curword= s:NetrwGetWord()
11409 if curword == "./" || curword == "../"
11410 let ctr= ctr + 1
11411 continue
11412 endif
11413 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011414 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011415 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011416 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011417 let all= 1
11418 endif
11419 let ctr= ctr + 1
11420 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011421 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 endif
11423
11424 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011425" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011427 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011428" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11429 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011431 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432
11433" call Dret("s:NetrwLocalRm")
11434endfun
11435
11436" ---------------------------------------------------------------------
11437" s:NetrwLocalRmFile: remove file fname given the path {{{2
11438" Give confirmation prompt unless all==1
11439fun! s:NetrwLocalRmFile(path,fname,all)
11440" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011441
Bram Moolenaar446cb832008-06-24 21:56:24 +000011442 let all= a:all
11443 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011444 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011445 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011447
11448 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11449 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011451 if !all
11452 echohl Statement
11453 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011454 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455 call inputrestore()
11456 echohl NONE
11457 if ok == ""
11458 let ok="no"
11459 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011460" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011462" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011463 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011464 let all= 1
11465 endif
11466 endif
11467
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011468 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011469 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011470" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011471 endif
11472
11473 else
11474 " attempt to remove directory
11475 if !all
11476 echohl Statement
11477 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011478 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011479 call inputrestore()
11480 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11481 if ok == ""
11482 let ok="no"
11483 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011484 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011485 let all= 1
11486 endif
11487 endif
11488 let rmfile= substitute(rmfile,'[\/]$','','e')
11489
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011490 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011491 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011492 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011493 endif
11494 endif
11495 endif
11496
11497" call Dret("s:NetrwLocalRmFile ".ok)
11498 return ok
11499endfun
11500
Bram Moolenaar85850f32019-07-19 22:05:51 +020011501" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011502" Support Functions: {{{1
11503
Bram Moolenaar488c6512005-08-11 20:09:58 +000011504" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011505" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11506" 0: marked file list of current buffer
11507" 1: marked file target
11508fun! netrw#Access(ilist)
11509 if a:ilist == 0
11510 if exists("s:netrwmarkfilelist_".bufnr('%'))
11511 return s:netrwmarkfilelist_{bufnr('%')}
11512 else
11513 return "no-list-buf#".bufnr('%')
11514 endif
11515 elseif a:ilist == 1
11516 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011517 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011518endfun
11519
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011520" ---------------------------------------------------------------------
11521" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11522fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011523 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524endfun
11525
Bram Moolenaara6878372014-03-22 21:02:50 +010011526" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011527" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11528" I expect this function to be used in
11529" :PChkAssert netrw#Expose("netrwmarkfilelist")
11530" for example.
11531fun! netrw#Expose(varname)
11532" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011533 if exists("s:".a:varname)
11534 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011535" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011536 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011537" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011538 if type(retval) == 3
11539 let retval = copy(retval)
11540 let i = 0
11541 while i < len(retval)
11542 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11543 let i = i + 1
11544 endwhile
11545 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011546" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011547 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011548 else
11549" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011550 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011551 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011552" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011553 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011554 endif
11555
11556" call Dret("netrw#Expose ".string(retval))
11557 return retval
11558endfun
11559
11560" ---------------------------------------------------------------------
11561" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11562fun! netrw#Modify(varname,newvalue)
11563" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11564 exe "let s:".a:varname."= ".string(a:newvalue)
11565" call Dret("netrw#Modify")
11566endfun
11567
11568" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011569" netrw#RFC2396: converts %xx into characters {{{2
11570fun! netrw#RFC2396(fname)
11571" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011572 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011573" call Dret("netrw#RFC2396 ".fname)
11574 return fname
11575endfun
11576
11577" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011578" netrw#UserMaps: supports user-specified maps {{{2
11579" see :help function()
11580"
11581" g:Netrw_UserMaps is a List with members such as:
11582" [[keymap sequence, function reference],...]
11583"
11584" The referenced function may return a string,
11585" refresh : refresh the display
11586" -other- : this string will be executed
11587" or it may return a List of strings.
11588"
11589" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011590" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591" Related functions:
11592" netrw#Expose(varname) -- see s:varname variables
11593" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11594" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11595fun! netrw#UserMaps(islocal)
11596" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11597" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11598
11599 " set up usermaplist
11600 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11601" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11602 for umap in g:Netrw_UserMaps
11603" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11604" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11605 " if umap[0] is a string and umap[1] is a string holding a function name
11606 if type(umap[0]) == 1 && type(umap[1]) == 1
11607" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11608 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11609 else
11610 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11611 endif
11612 endfor
11613 endif
11614" call Dret("netrw#UserMaps")
11615endfun
11616
11617" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011618" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11619fun! netrw#WinPath(path)
11620" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011621 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011622 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011623 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011624 " remove trailing slash (Win95)
11625 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11626 " remove escaped spaces
11627 let path = substitute(path, '\ ', ' ', 'g')
11628 " convert slashes to backslashes
11629 let path = substitute(path, '/', '\', 'g')
11630 else
11631 let path= a:path
11632 endif
11633" call Dret("netrw#WinPath <".path.">")
11634 return path
11635endfun
11636
11637" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011638" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11639fun! s:StripTrailingSlash(path)
11640 " remove trailing slash
11641 return substitute(a:path, '[/\\]$', '', 'g')
11642endfun
11643
Travis Sheltone34d0e32024-07-30 21:08:56 +020011644" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011645" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11646" cb : bl2mf=0 add marked files to buffer list
11647" cB : bl2mf=1 use bufferlist to mark files
11648" (mnemonic: cb = copy (marked files) to buffer list)
11649fun! s:NetrwBadd(islocal,bl2mf)
11650" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11651 if a:bl2mf
11652 " cB: add buffer list to marked files
11653 redir => bufl
11654 ls
11655 redir END
11656 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11657 for fname in bufl
11658 call s:NetrwMarkFile(a:islocal,fname)
11659 endfor
11660 else
11661 " cb: add marked files to buffer list
11662 for fname in s:netrwmarkfilelist_{bufnr("%")}
11663" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11664 exe "badd ".fnameescape(fname)
11665 endfor
11666 let curbufnr = bufnr("%")
11667 let curdir = s:NetrwGetCurdir(a:islocal)
11668 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11669 endif
11670" call Dret("s:NetrwBadd")
11671endfun
11672
11673" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011674" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11675fun! s:ComposePath(base,subdir)
11676" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11677
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011678 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011679" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011680 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011681 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011682 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011683 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011684 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011685 endif
11686
Bram Moolenaar85850f32019-07-19 22:05:51 +020011687 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011688 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011689" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690 let ret= a:subdir
11691
Nir Lichtman1e34b952024-05-08 19:19:34 +020011692 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011694 if a:base =~ '[/\\]$'
11695 let ret= a:base.a:subdir
11696 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011698 endif
11699
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700 elseif a:base =~ '^\a\{3,}://'
11701" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011702 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11703 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11704 if a:subdir == '../'
11705 if curpath =~ '[^/]/[^/]\+/$'
11706 let curpath= substitute(curpath,'[^/]\+/$','','')
11707 else
11708 let curpath=""
11709 endif
11710 let ret= urlbase.curpath
11711 else
11712 let ret= urlbase.curpath.a:subdir
11713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011714" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11715" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11716" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011717
11718 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011720 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11721 if a:base =~ '^//'
11722 " keeping initial '//' for the benefit of network share listing support
11723 let ret= '/'.ret
11724 endif
11725 let ret= simplify(ret)
11726 endif
11727
11728" call Dret("s:ComposePath ".ret)
11729 return ret
11730endfun
11731
11732" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011733" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11734" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11735fun! s:DeleteBookmark(fname)
11736" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11737 call s:MergeBookmarks()
11738
11739 if exists("g:netrw_bookmarklist")
11740 let indx= index(g:netrw_bookmarklist,a:fname)
11741 if indx == -1
11742 let indx= 0
11743 while indx < len(g:netrw_bookmarklist)
11744 if g:netrw_bookmarklist[indx] =~ a:fname
11745 call remove(g:netrw_bookmarklist,indx)
11746 let indx= indx - 1
11747 endif
11748 let indx= indx + 1
11749 endwhile
11750 else
11751 " remove exact match
11752 call remove(g:netrw_bookmarklist,indx)
11753 endif
11754 endif
11755
11756" call Dret("s:DeleteBookmark")
11757endfun
11758
11759" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011760" s:FileReadable: o/s independent filereadable {{{2
11761fun! s:FileReadable(fname)
11762" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11763
11764 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011767 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011768 endif
11769
11770" call Dret("s:FileReadable ".ret)
11771 return ret
11772endfun
11773
11774" ---------------------------------------------------------------------
11775" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11776" Places correct suffix on end of temporary filename,
11777" using the suffix provided with fname
11778fun! s:GetTempfile(fname)
11779" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11780
11781 if !exists("b:netrw_tmpfile")
11782 " get a brand new temporary filename
11783 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011785
Bram Moolenaarc236c162008-07-13 17:41:49 +000011786 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788
Bram Moolenaar9964e462007-05-05 17:54:07 +000011789 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011790 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11791" 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 +010011792 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793" call Dret("s:GetTempfile getcwd<".getcwd().">")
11794 return ""
11795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011796
Bram Moolenaar9964e462007-05-05 17:54:07 +000011797 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011798 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011803 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011804 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805 if !exists("+shellslash") || !&ssl
11806 let tmpfile = substitute(tmpfile,'/','\','g')
11807 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 endif
11811 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011812" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 else
11814 " re-use temporary filename
11815 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 endif
11818
11819 " use fname's suffix for the temporary file
11820 if a:fname != ""
11821 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011823 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011825 elseif a:fname =~ '.txz$'
11826 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 else
11828 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11829 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11836 endif
11837 endif
11838
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011839" 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 +000011840" call Dret("s:GetTempfile <".tmpfile.">")
11841 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011842endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011843
11844" ---------------------------------------------------------------------
11845" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011846" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011848" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011849 if s:user == ""
11850 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11851 else
11852 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11853 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011855 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011856 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011857 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011858 else
11859 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11860 endif
11861" call Dret("s:MakeSshCmd <".sshcmd.">")
11862 return sshcmd
11863endfun
11864
11865" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011866" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11867fun! s:MakeBookmark(fname)
11868" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11869
11870 if !exists("g:netrw_bookmarklist")
11871 let g:netrw_bookmarklist= []
11872 endif
11873
11874 if index(g:netrw_bookmarklist,a:fname) == -1
11875 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011876 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011877 call add(g:netrw_bookmarklist,a:fname.'/')
11878 elseif a:fname !~ '/'
11879 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11880 else
11881 call add(g:netrw_bookmarklist,a:fname)
11882 endif
11883 call sort(g:netrw_bookmarklist)
11884 endif
11885
11886" call Dret("s:MakeBookmark")
11887endfun
11888
11889" ---------------------------------------------------------------------
11890" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11891fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011893 " get bookmarks from .netrwbook file
11894 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895 if filereadable(s:NetrwFile(savefile))
11896" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011898" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011899 NetrwKeepj call delete(savefile)
11900 endif
11901" call Dret("s:MergeBookmarks")
11902endfun
11903
11904" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011905" s:NetrwBMShow: {{{2
11906fun! s:NetrwBMShow()
11907" call Dfunc("s:NetrwBMShow()")
11908 redir => bmshowraw
11909 menu
11910 redir END
11911 let bmshowlist = split(bmshowraw,'\n')
11912 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011913 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011914 if bmshowfuncs != []
11915 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011916 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011917 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011919 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011920 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11922endfun
11923
11924" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011925" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011926fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011927 if !exists("w:netrw_liststyle")
11928 let w:netrw_liststyle= g:netrw_liststyle
11929 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011930" 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 +020011931
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011932" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11933
Bram Moolenaaradc21822011-04-01 18:03:16 +020011934 if &ft != "netrw"
11935 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11936 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011937" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011939 elseif g:netrw_cursor == 8
11940 if w:netrw_liststyle == s:WIDELIST
11941 setl cursorline
11942 setl cursorcolumn
11943 else
11944 setl cursorline
11945 endif
11946 elseif g:netrw_cursor == 7
11947 setl cursorline
11948 elseif g:netrw_cursor == 6
11949 if w:netrw_liststyle == s:WIDELIST
11950 setl cursorline
11951 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011952 elseif g:netrw_cursor == 4
11953 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011955 setl cursorline
11956 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957
11958 elseif g:netrw_cursor == 3
11959 " thin-long-tree: cursorline, user's cursorcolumn
11960 " wide : cursorline, cursorcolumn
11961 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011963 setl cursorline
11964 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" 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 +020011967 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 endif
11969
11970 elseif g:netrw_cursor == 2
11971 " thin-long-tree: cursorline, user's cursorcolumn
11972 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011974 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975
11976 elseif g:netrw_cursor == 1
11977 " thin-long-tree: user's cursorline, user's cursorcolumn
11978 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011981 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011983" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011984 endif
11985
11986 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011988" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989 let &l:cursorline = s:netrw_usercul
11990 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011991 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011992
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011993" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011995endfun
11996
11997" ---------------------------------------------------------------------
11998" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11999fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012000" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001 if exists("s:netrw_usercul")
12002 let &l:cursorline = s:netrw_usercul
12003 endif
12004 if exists("s:netrw_usercuc")
12005 let &l:cursorcolumn = s:netrw_usercuc
12006 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012007" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012008" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12009endfun
12010
Christian Brabandt62f7b552024-06-23 20:23:40 +020012011" s:RestoreRegister: restores all registers given in the dict {{{2
12012fun! s:RestoreRegister(dict)
12013 for [key, val] in items(a:dict)
12014 if key == 'unnamed'
12015 let key = ''
12016 endif
12017 call setreg(key, val[0], val[1])
12018 endfor
12019endfun
12020
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012021" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012022" s:NetrwDelete: Deletes a file. {{{2
12023" Uses Steve Hall's idea to insure that Windows paths stay
12024" acceptable. No effect on Unix paths.
12025" Examples of use: let result= s:NetrwDelete(path)
12026fun! s:NetrwDelete(path)
12027" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12028
Bram Moolenaar5c736222010-01-06 20:54:52 +010012029 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012030 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031 if exists("+shellslash")
12032 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012033 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012034 let result = delete(path)
12035 let &shellslash = sskeep
12036 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012037" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012038 let result= delete(path)
12039 endif
12040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012041" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012042 let result= delete(path)
12043 endif
12044 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012045 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012046 endif
12047
12048" call Dret("s:NetrwDelete ".result)
12049 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012050endfun
12051
12052" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012053" s:NetrwBufRemover: removes a buffer that: {{{2s
12054" has buffer-id > 1
12055" is unlisted
12056" is unnamed
12057" does not appear in any window
12058fun! s:NetrwBufRemover(bufid)
12059" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12060" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12061" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12062" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12063" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12064
yasuda4dbb2662023-10-04 20:50:35 +020012065 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012066" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012067 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012068 endif
12069
12070" call Dret("s:NetrwBufRemover")
12071endfun
12072
12073" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012074" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012075fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012076" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012077" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012078
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012079 " Clean out the last buffer:
12080 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12081 " If so, delete it.
12082 call s:NetrwBufRemover(bufnr("$"))
12083
Bram Moolenaar446cb832008-06-24 21:56:24 +000012084 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012085" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012086 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12087 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12088 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12089 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12090 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12091 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12092 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12093 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12094 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12095 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12096 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12097 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12098 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12099 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12100 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12101 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12102
Bram Moolenaar85850f32019-07-19 22:05:51 +020012103 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012104" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012105 " when tree listing uses file TreeListing... a new buffer is made.
12106 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012107 " COMBAK: this causes a problem, see P43
12108" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012109 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012110 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012111 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012112" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012113 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012114
Bram Moolenaar446cb832008-06-24 21:56:24 +000012115 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012116" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012117 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12118 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12119 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12120 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12121 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12122 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12123 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12124 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12125 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12126 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12127 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12128 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12129 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12130 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12131 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12132 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12133
Bram Moolenaar5c736222010-01-06 20:54:52 +010012134 if a:0 > 0
12135 let b:netrw_curdir= a:1
12136 if b:netrw_curdir =~ '/$'
12137 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012138 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012139 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012140 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012141 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12142 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012143 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012144 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012145 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012146 endif
12147 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012148 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12149 let &l:bexpr = "netrw#BalloonHelp()"
12150 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012151
Bram Moolenaar8d043172014-01-23 14:24:41 +010012152" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012153endfun
12154
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012155" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012156" s:NetrwExe: executes a string using "!" {{{2
12157fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012158" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012159 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012160" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012161 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12162 set shell& shellcmdflag& shellxquote& shellxescape&
12163 set shellquote& shellpipe& shellredir& shellslash&
12164 exe a:cmd
12165 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12166 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012167" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012168 exe a:cmd
12169 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012170 if v:shell_error
12171 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12172 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012173" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012174endfun
12175
12176" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012177" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12178fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012179 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012180" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012181 let curbuf = bufnr("%")
12182 let curwin = winnr()
12183 let iwin = 1
12184 while iwin <= winnr("$")
12185 exe iwin."wincmd w"
12186 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12187 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12188 let winvars= w:
12189 break
12190 endif
12191 let iwin= iwin + 1
12192 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012193 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012194 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012195" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012196 for k in keys(winvars)
12197 let w:{k}= winvars[k]
12198 endfor
12199 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012200" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012201 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012202endfun
12203
Bram Moolenaara6878372014-03-22 21:02:50 +010012204" ---------------------------------------------------------------------
12205" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012206" Returns: 0=success
12207" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012208fun! s:NetrwLcd(newdir)
12209" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012210" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012211
Bram Moolenaar85850f32019-07-19 22:05:51 +020012212 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012213 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012214 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012215 catch /^Vim\%((\a\+)\)\=:E344/
12216 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12217 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012218 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12220 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012221 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12223 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012224 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012225 endif
12226 endif
12227 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012228 let err472= 1
12229 endtry
12230
12231 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012232 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12233 if exists("w:netrw_prvdir")
12234 let a:newdir= w:netrw_prvdir
12235 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012236 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012237" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012238 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012239" 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 +010012240 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012242" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12243 return -1
12244 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012245
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012246" call Decho("getcwd <".getcwd().">")
12247" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012248" call Dret("s:NetrwLcd 0")
12249 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012250endfun
12251
Bram Moolenaar9964e462007-05-05 17:54:07 +000012252" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012253" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12254" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12255fun! s:NetrwSaveWordPosn()
12256" call Dfunc("NetrwSaveWordPosn()")
12257 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12258" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12259endfun
12260
12261" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012262" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12263" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12264fun! s:NetrwHumanReadable(sz)
12265" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12266
12267 if g:netrw_sizestyle == 'h'
12268 if a:sz >= 1000000000
12269 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12270 elseif a:sz >= 10000000
12271 let sz = printf("%d",a:sz/1000000)."m"
12272 elseif a:sz >= 1000000
12273 let sz = printf("%.1f",a:sz/1000000.0)."m"
12274 elseif a:sz >= 10000
12275 let sz = printf("%d",a:sz/1000)."k"
12276 elseif a:sz >= 1000
12277 let sz = printf("%.1f",a:sz/1000.0)."k"
12278 else
12279 let sz= a:sz
12280 endif
12281
12282 elseif g:netrw_sizestyle == 'H'
12283 if a:sz >= 1073741824
12284 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12285 elseif a:sz >= 10485760
12286 let sz = printf("%d",a:sz/1048576)."M"
12287 elseif a:sz >= 1048576
12288 let sz = printf("%.1f",a:sz/1048576.0)."M"
12289 elseif a:sz >= 10240
12290 let sz = printf("%d",a:sz/1024)."K"
12291 elseif a:sz >= 1024
12292 let sz = printf("%.1f",a:sz/1024.0)."K"
12293 else
12294 let sz= a:sz
12295 endif
12296
12297 else
12298 let sz= a:sz
12299 endif
12300
12301" call Dret("s:NetrwHumanReadable ".sz)
12302 return sz
12303endfun
12304
12305" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012306" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12307" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12308fun! s:NetrwRestoreWordPosn()
12309" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012310 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012311" call Dret("NetrwRestoreWordPosn")
12312endfun
12313
12314" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012315" s:RestoreBufVars: {{{2
12316fun! s:RestoreBufVars()
12317" call Dfunc("s:RestoreBufVars()")
12318
12319 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12320 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12321 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12322 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12323 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12324 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12325
12326" call Dret("s:RestoreBufVars")
12327endfun
12328
12329" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012330" s:RemotePathAnalysis: {{{2
12331fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012332" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012333
Bram Moolenaara6878372014-03-22 21:02:50 +010012334 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012335 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012336 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012337 let s:user = substitute(a:dirname,dirpat,'\3','')
12338 let s:machine = substitute(a:dirname,dirpat,'\4','')
12339 let s:port = substitute(a:dirname,dirpat,'\5','')
12340 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012341 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012342 if s:machine =~ '@'
12343 let dirpat = '^\(.*\)@\(.\{-}\)$'
12344 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12345 let s:machine = substitute(s:machine,dirpat,'\2','')
12346 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012347
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012348" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12349" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12350" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12351" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12352" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12353" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012354
12355" call Dret("s:RemotePathAnalysis")
12356endfun
12357
12358" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012359" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12360" Returns status
12361" Runs system() on
12362" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012363" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012364fun! s:RemoteSystem(cmd)
12365" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12366 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012367 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 +000012368 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012369 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012370 else
12371 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12372 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12373 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012374 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012375 else
12376 let cmd= cmd.' '
12377 endif
12378 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012380 let ret= system(cmd)
12381 endif
12382" call Dret("s:RemoteSystem ".ret)
12383 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012384endfun
12385
12386" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012387" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388fun! s:RestoreWinVars()
12389" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012390 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012391 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12392 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12393 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12394 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12395 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12396 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12397 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12398 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12399 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12400 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12401 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12402 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012403 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12404 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012405 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12406 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12407 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12408" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012409endfun
12410
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012411" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012412" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12413"
12414" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12415" is true) and a command, :Rexplore, which call this function.
12416"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012417" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012418"
12419" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012420fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012421 if exists("s:netrwdrag")
12422 return
12423 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012424" 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 +010012425" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12426" 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 +010012427
12428 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012429 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012430" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012431 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012432 unlet w:netrw_rexfile
12433" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012434 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12437" 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 +020012438 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012439
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012440 " ---------------------------
12441 " :Rex issued while in a file
12442 " ---------------------------
12443
Bram Moolenaara6878372014-03-22 21:02:50 +010012444 " record current file so :Rex can return to it from netrw
12445 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012446" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012447
12448 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012449" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012450 return
12451 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" 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 +020012453 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012454 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012455 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012456 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012457 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012458 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012459 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012460 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012461 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012462" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12463 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012464" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12465 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012466 if exists("s:rexposn_".bufnr('%'))
12467 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012468 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012469 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012470" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012471 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012472
Bram Moolenaar85850f32019-07-19 22:05:51 +020012473 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12474 if exists("s:explore_match")
12475 exe "2match netrwMarkFile /".s:explore_match."/"
12476 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012477 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012478
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012479" 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 +010012480" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012481endfun
12482
12483" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012484" s:SaveBufVars: save selected b: variables to s: variables {{{2
12485" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012486fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012487" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012488
12489 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12490 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12491 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12492 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12493 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12494 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12495
12496" call Dret("s:SaveBufVars")
12497endfun
12498
12499" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012500" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12501fun! s:SavePosn(posndict)
12502" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12503
Bram Moolenaar85850f32019-07-19 22:05:51 +020012504 if !exists("a:posndict[bufnr('%')]")
12505 let a:posndict[bufnr("%")]= []
12506 endif
12507" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12508 call add(a:posndict[bufnr("%")],winsaveview())
12509" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012510
12511" call Dret("s:SavePosn posndict")
12512 return a:posndict
12513endfun
12514
12515" ---------------------------------------------------------------------
12516" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12517fun! s:RestorePosn(posndict)
12518" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012519 if exists("a:posndict")
12520 if has_key(a:posndict,bufnr("%"))
12521" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12522 let posnlen= len(a:posndict[bufnr("%")])
12523 if posnlen > 0
12524 let posnlen= posnlen - 1
12525" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12526 call winrestview(a:posndict[bufnr("%")][posnlen])
12527 call remove(a:posndict[bufnr("%")],posnlen)
12528" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12529 endif
12530 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012531 endif
12532" call Dret("s:RestorePosn")
12533endfun
12534
12535" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012536" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012537fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012538" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012539 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12540 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12541 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12542 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12543 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12544 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12545 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12546 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12547 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12548 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12549 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12550 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12551 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12552 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12553 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12554 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12555 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12556 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12557" call Dret("s:SaveWinVars")
12558endfun
12559
12560" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012561" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012562" To allow separate windows to have their own activities, such as
12563" Explore **/pattern, several variables have been made window-oriented.
12564" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012565" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012566" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012567fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012568" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012569 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12570 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12571 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12572 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12573 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12574 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12575 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12576 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12577 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12578 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12579" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012580endfun
12581
12582" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012583" s:SetRexDir: set directory for :Rexplore {{{2
12584fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012585" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012586 let w:netrw_rexdir = a:dirname
12587 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012588 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012589" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12590" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012591" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012592" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012593" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012594endfun
12595
12596" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012597" s:ShowLink: used to modify thin and tree listings to show links {{{2
12598fun! s:ShowLink()
12599" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012600" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12601" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012602 if exists("b:netrw_curdir")
12603 norm! $?\a
12604 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12605 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012606" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12607" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12608" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12609 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012610 let dirlen = strlen(b:netrw_curdir)
12611 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012613 endif
12614 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012615" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12616" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012617 setl noro ma
12618 call setline(".",modline)
12619 setl ro noma nomod
12620 endif
12621" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12622endfun
12623
12624" ---------------------------------------------------------------------
12625" s:ShowStyle: {{{2
12626fun! s:ShowStyle()
12627 if !exists("w:netrw_liststyle")
12628 let liststyle= g:netrw_liststyle
12629 else
12630 let liststyle= w:netrw_liststyle
12631 endif
12632 if liststyle == s:THINLIST
12633 return s:THINLIST.":thin"
12634 elseif liststyle == s:LONGLIST
12635 return s:LONGLIST.":long"
12636 elseif liststyle == s:WIDELIST
12637 return s:WIDELIST.":wide"
12638 elseif liststyle == s:TREELIST
12639 return s:TREELIST.":tree"
12640 else
12641 return 'n/a'
12642 endif
12643endfun
12644
12645" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12647" Solution from Nicolai Weibull, vim docs (:help strlen()),
12648" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012649fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12651
12652 if v:version >= 703 && exists("*strdisplaywidth")
12653 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012654
Bram Moolenaar8d043172014-01-23 14:24:41 +010012655 elseif type(g:Align_xstrlen) == 1
12656 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12657 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012658
Bram Moolenaar8d043172014-01-23 14:24:41 +010012659 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012660 " number of codepoints (Latin a + combining circumflex is two codepoints)
12661 " (comment from TM, solution from NW)
12662 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012663
Bram Moolenaar8d043172014-01-23 14:24:41 +010012664 elseif g:Align_xstrlen == 2
12665 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012666 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12667 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012668 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012669
Bram Moolenaar8d043172014-01-23 14:24:41 +010012670 elseif g:Align_xstrlen == 3
12671 " virtual length (counting, for instance, tabs as anything between 1 and
12672 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012673 " preceded by lam, one otherwise, etc.)
12674 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675 let modkeep= &l:mod
12676 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012677 call setline(line("."),a:x)
12678 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012679 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012680 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012681 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012682
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 else
12684 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012685 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012686 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012687" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012688 return ret
12689endfun
12690
12691" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012692" s:ShellEscape: shellescape(), or special windows handling {{{2
12693fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012694 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012695 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12696 endif
12697 let f = a:0 > 0 ? a:1 : 0
12698 return shellescape(a:s, f)
12699endfun
12700
12701" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012702" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012703fun! s:TreeListMove(dir)
12704" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012705 let curline = getline('.')
12706 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12707 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12708 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12709 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12710 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12711 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12712" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12713" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12714" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12715" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12716" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12717 " COMBAK : need to handle when on a directory
12718 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012719 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012720 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012721 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012722 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012723" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 elseif a:dir == '[]' && nxtline != ''
12725 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012726" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012727 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12728 if nl != 0
12729 NetrwKeepj norm! k
12730 else
12731 NetrwKeepj norm! G
12732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012733" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012734 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012735 endif
12736
12737" call Dret("s:TreeListMove")
12738endfun
12739
12740" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012741" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12742" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12743" can't be called except via emenu. But due to locale, that menu line may not be called
12744" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12745fun! s:UpdateBuffersMenu()
12746" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012747 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012748 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012749 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012750 catch /^Vim\%((\a\+)\)\=:E/
12751 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012752 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012753 endtry
12754 endif
12755" call Dret("s:UpdateBuffersMenu")
12756endfun
12757
12758" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012759" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012760" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012761fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012762" call Dfunc("s:UseBufWinVars()")
12763 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012764 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12765 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12766 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12767 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12768 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12769 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12770 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12771 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12772 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 +000012773" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012774endfun
12775
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012776" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012777" s:UserMaps: supports user-defined UserMaps {{{2
12778" * calls a user-supplied funcref(islocal,curdir)
12779" * interprets result
12780" See netrw#UserMaps()
12781fun! s:UserMaps(islocal,funcname)
12782" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12783
12784 if !exists("b:netrw_curdir")
12785 let b:netrw_curdir= getcwd()
12786 endif
12787 let Funcref = function(a:funcname)
12788 let result = Funcref(a:islocal)
12789
12790 if type(result) == 1
12791 " if result from user's funcref is a string...
12792" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12793 if result == "refresh"
12794" call Decho("refreshing display",'~'.expand("<slnum>"))
12795 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12796 elseif result != ""
12797" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12798 exe result
12799 endif
12800
12801 elseif type(result) == 3
12802 " if result from user's funcref is a List...
12803" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12804 for action in result
12805 if action == "refresh"
12806" call Decho("refreshing display",'~'.expand("<slnum>"))
12807 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12808 elseif action != ""
12809" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12810 exe action
12811 endif
12812 endfor
12813 endif
12814
12815" call Dret("s:UserMaps")
12816endfun
12817
Bram Moolenaar85850f32019-07-19 22:05:51 +020012818" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012819" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012820" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012821let &cpo= s:keepcpo
12822unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012823
Bram Moolenaar85850f32019-07-19 22:05:51 +020012824" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012825" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012826" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012827" vim:ts=8 fdm=marker