blob: 32912c8c743d777ebc7ec5d57c4740b6f55237a4 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Travis Sheltone34d0e32024-07-30 21:08:56 +020032" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010033" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000034" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010035" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000036" Permission is hereby granted to use and distribute this code,
37" with or without modifications, provided that this copyright
38" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000039" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000040" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000041" expressed or implied. By using this plugin, you agree that
42" in no event will the copyright holder be liable for any damages
43" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010044"
45" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
46" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
47"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020048"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000049"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000050" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000051" (James 1:22 RSV)
52" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000053" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000054if &cp || exists("g:loaded_netrw")
55 finish
56endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020057
58" Check that vim has patches that netrw requires.
59" Patches needed for v7.4: 1557, and 213.
60" (netrw will benefit from vim's having patch#656, too)
61let s:needspatches=[1557,213]
62if exists("s:needspatches")
63 for ptch in s:needspatches
64 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
65 if !exists("s:needpatch{ptch}")
66 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
67 endif
68 let s:needpatch{ptch}= 1
69 finish
70 endif
71 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020072endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020073
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010074let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000075
Bram Moolenaar1afcace2005-11-25 19:54:28 +000076let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010077setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020078"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010079"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010080"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000082" ======================
83" Netrw Variables: {{{1
84" ======================
85
Bram Moolenaar071d4272004-06-13 20:20:40 +000086" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020087" netrw#ErrorMsg: {{{2
88" 0=note = s:NOTE
89" 1=warning = s:WARNING
90" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010091" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
92" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
93" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010094" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020095fun! netrw#ErrorMsg(level,msg,errnum)
96" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
97
98 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020099" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200100 return
101 endif
102
103 if a:level == 1
104 let level= "**warning** (netrw) "
105 elseif a:level == 2
106 let level= "**error** (netrw) "
107 else
108 let level= "**note** (netrw) "
109 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100110" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200111
Damienb4d11642024-08-15 22:00:45 +0200112 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200113 " use popup window
114 if type(a:msg) == 3
115 let msg = [level]+a:msg
116 else
117 let msg= level.a:msg
118 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200119 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200120 let s:popuperr_text= ""
121 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122 " (default) netrw creates a one-line window to show error/warning
123 " messages (reliably displayed)
124
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100125 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100127" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128
129 " getting messages out reliably is just plain difficult!
130 " This attempt splits the current window, creating a one line window.
131 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100132" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100134" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100136 if type(a:msg) == 3
137 for msg in a:msg
138 NetrwKeepj call setline(line("$")+1,level.msg)
139 endfor
140 else
141 NetrwKeepj call setline(line("$")+1,level.a:msg)
142 endif
143 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100145" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 bo 1split
147 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200148 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200149 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100150 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100151" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100153 if type(a:msg) == 3
154 for msg in a:msg
155 NetrwKeepj call setline(line("$")+1,level.msg)
156 endfor
157 else
158 NetrwKeepj call setline(line("$"),level.a:msg)
159 endif
160 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200161 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100162" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200163 if &fo !~ '[ta]'
164 syn clear
165 syn match netrwMesgNote "^\*\*note\*\*"
166 syn match netrwMesgWarning "^\*\*warning\*\*"
167 syn match netrwMesgError "^\*\*error\*\*"
168 hi link netrwMesgWarning WarningMsg
169 hi link netrwMesgError Error
170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100171" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200172 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200173
174 else
175 " (optional) netrw will show messages using echomsg. Even if the
176 " message doesn't appear, at least it'll be recallable via :messages
177" redraw!
178 if a:level == s:WARNING
179 echohl WarningMsg
180 elseif a:level == s:ERROR
181 echohl Error
182 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100183
184 if type(a:msg) == 3
185 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100186 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100187 endfor
188 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100189 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100190 endif
191
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100192" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200193 echohl None
194 endif
195
196" call Dret("netrw#ErrorMsg")
197endfun
198
199" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100200" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100201" Loosely, varname = value.
202fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100203" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100204 if !exists(a:varname)
205 if type(a:value) == 0
206 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200207 elseif type(a:value) == 1 && a:value =~ '^[{[]'
208 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100209 elseif type(a:value) == 1
210 exe "let ".a:varname."="."'".a:value."'"
211 else
212 exe "let ".a:varname."=".a:value
213 endif
214 endif
215endfun
216
217" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000218" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200219call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000220if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100221 call s:NetrwInit("s:THINLIST",0)
222 call s:NetrwInit("s:LONGLIST",1)
223 call s:NetrwInit("s:WIDELIST",2)
224 call s:NetrwInit("s:TREELIST",3)
225 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000226endif
227
Damien7c754112024-08-15 21:58:57 +0200228let s:NOTE = 0
229let s:WARNING = 1
230let s:ERROR = 2
231call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
232
Bram Moolenaar9964e462007-05-05 17:54:07 +0000233" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200234" Default option values: {{{2
235let g:netrw_localcopycmdopt = ""
236let g:netrw_localcopydircmdopt = ""
237let g:netrw_localmkdiropt = ""
238let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200239
240" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000241" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200242if exists("*popup_atcursor")
243\ && has("syntax")
244\ && exists("g:syntax_on")
245\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200246 call s:NetrwInit("g:netrw_use_errorwindow",2)
247else
248 call s:NetrwInit("g:netrw_use_errorwindow",1)
249endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200250
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000251if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100252 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000253 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254 elseif executable("curl")
255 let g:netrw_dav_cmd = "curl"
256 else
257 let g:netrw_dav_cmd = ""
258 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000260if !exists("g:netrw_fetch_cmd")
261 if executable("fetch")
262 let g:netrw_fetch_cmd = "fetch -o"
263 else
264 let g:netrw_fetch_cmd = ""
265 endif
266endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100267if !exists("g:netrw_file_cmd")
268 if executable("elinks")
269 call s:NetrwInit("g:netrw_file_cmd","elinks")
270 elseif executable("links")
271 call s:NetrwInit("g:netrw_file_cmd","links")
272 endif
273endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000274if !exists("g:netrw_ftp_cmd")
275 let g:netrw_ftp_cmd = "ftp"
276endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200277let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200278if !exists("g:netrw_ftp_options")
279 let g:netrw_ftp_options= "-i -n"
280endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000281if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100282 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100283 let g:netrw_http_cmd = "wget"
284 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100285 elseif executable("curl")
286 let g:netrw_http_cmd = "curl"
287 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200288 elseif executable("elinks")
289 let g:netrw_http_cmd = "elinks"
290 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000291 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100292 let g:netrw_http_cmd = "fetch"
293 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200294 elseif executable("links")
295 let g:netrw_http_cmd = "links"
296 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000297 else
298 let g:netrw_http_cmd = ""
299 endif
300endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100301call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100302call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100303call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
304call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200305call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200306if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200307 if executable("scp")
308 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
309 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200310 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200311 else
312 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
313 endif
314endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100315call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
316call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000317
Nir Lichtman1e34b952024-05-08 19:19:34 +0200318if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000319 \ && exists("g:netrw_use_nt_rcp")
320 \ && g:netrw_use_nt_rcp
321 \ && executable( $SystemRoot .'/system32/rcp.exe')
322 let s:netrw_has_nt_rcp = 1
323 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000324else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000325 let s:netrw_has_nt_rcp = 0
326 let s:netrw_rcpmode = ''
327endif
328
329" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000330" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000331" Cygwin Detection ------- {{{3
332if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200333 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
334 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335 else
336 let g:netrw_cygwin= 0
337 endif
338endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000339" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100340call s:NetrwInit("g:netrw_alto" , &sb)
341call s:NetrwInit("g:netrw_altv" , &spr)
342call s:NetrwInit("g:netrw_banner" , 1)
343call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200344call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200346call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_compress" , "gzip")
348call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200349if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
350 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
351 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000352endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200353call s:NetrwInit("g:netrw_cursor" , 2)
354let s:netrw_usercul = &cursorline
355let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200356"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100357call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000358" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200359call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200360call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200361call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100362call s:NetrwInit("g:netrw_dirhistmax" , 10)
363call s:NetrwInit("g:netrw_fastbrowse" , 1)
364call 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 +0000365if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000366 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
367 let g:netrw_ftp_list_cmd = "ls -lF"
368 let g:netrw_ftp_timelist_cmd = "ls -tlF"
369 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000370 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371 let g:netrw_ftp_list_cmd = "dir"
372 let g:netrw_ftp_timelist_cmd = "dir"
373 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000374 endif
375endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100376call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000377" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100378call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000379if !exists("g:netrw_ignorenetrc")
380 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
381 let g:netrw_ignorenetrc= 1
382 else
383 let g:netrw_ignorenetrc= 0
384 endif
385endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100386call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000387if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000388 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100389 if exists("g:netrw_list_cmd_options")
390 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
391 else
392 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
393 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000394 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200395 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100396 if exists("g:netrw_list_cmd_options")
397 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
398 else
399 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
400 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000401 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100402" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000403 let g:netrw_list_cmd= ""
404 endif
405endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100406call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000407" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200408if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200409 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200410 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
411endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100412if !exists("g:netrw_localcmdshell")
413 let g:netrw_localcmdshell= ""
414endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000415if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200416 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000417 if g:netrw_cygwin
418 let g:netrw_localcopycmd= "cp"
419 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000420 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000422 endif
423 elseif has("unix") || has("macunix")
424 let g:netrw_localcopycmd= "cp"
425 else
426 let g:netrw_localcopycmd= ""
427 endif
428endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200430 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200432 let g:netrw_localcopydircmd = "cp"
433 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000435 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200436 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100437 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200438 elseif has("unix")
439 let g:netrw_localcopydircmd = "cp"
440 let g:netrw_localcopydircmdopt= " -R"
441 elseif has("macunix")
442 let g:netrw_localcopydircmd = "cp"
443 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100444 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200445 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100446 endif
447endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200448if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100449 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200450 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
451endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200452if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200453 if g:netrw_cygwin
454 call s:NetrwInit("g:netrw_localmkdir","mkdir")
455 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000456 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200457 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200458 endif
459else
460 call s:NetrwInit("g:netrw_localmkdir","mkdir")
461endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200462call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200463if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200464 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200465 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
466endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000467if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200468 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000469 if g:netrw_cygwin
470 let g:netrw_localmovecmd= "mv"
471 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000472 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200473 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000474 endif
475 elseif has("unix") || has("macunix")
476 let g:netrw_localmovecmd= "mv"
477 else
478 let g:netrw_localmovecmd= ""
479 endif
480endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100481" following serves as an example for how to insert a version&patch specific test
482"if v:version < 704 || (v:version == 704 && !has("patch1107"))
483"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100484call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
485" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000486if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000487 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000488endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000489if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000490 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
491endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000492" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
494call s:NetrwInit("g:netrw_maxfilenamelen", 32)
495call s:NetrwInit("g:netrw_menu" , 1)
496call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200497call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100498call s:NetrwInit("g:netrw_retmap" , 0)
499if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
500 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200501elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100502 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
503else
504 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000505endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100506call s:NetrwInit("g:netrw_preview" , 0)
507call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100508call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100509call s:NetrwInit("g:netrw_sshport" , "-p")
510call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
511call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
512call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100513call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
514" Default values - q-s ---------- {{{3
515call s:NetrwInit("g:netrw_quickhelp",0)
516let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100517 \ "(create new) %:file d:directory",
518 \ "(windows split&open) o:horz v:vert p:preview",
519 \ "i:style qf:file info O:obtain r:reverse",
520 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
521 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
522 \ "(history) qb:list u:go up U:go down",
523 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
525call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100526if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
527 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
528else
529 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
530endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
532call s:NetrwInit("g:netrw_sort_options" , "")
533call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000534if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200536 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537 else
538 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000539 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000540endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541call s:NetrwInit("g:netrw_special_syntax" , 0)
542call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100543call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100544call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000545" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200547if !exists("g:netrw_xstrlen")
548 if exists("g:Align_xstrlen")
549 let g:netrw_xstrlen= g:Align_xstrlen
550 elseif exists("g:drawit_xstrlen")
551 let g:netrw_xstrlen= g:drawit_xstrlen
552 elseif &enc == "latin1" || !has("multi_byte")
553 let g:netrw_xstrlen= 0
554 else
555 let g:netrw_xstrlen= 1
556 endif
557endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100558call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200559call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100560call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200561if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000562" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000563" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100564call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200565if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200566 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200567else
Bram Moolenaarff034192013-04-24 18:51:19 +0200568 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200569endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200570call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100571call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
572call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100573if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100574 let s:treedepthstring= "│ "
575else
576 let s:treedepthstring= "| "
577endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200578call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000579
580" BufEnter event ignored by decho when following variable is true
581" Has a side effect that doau BufReadPost doesn't work, so
582" files read by network transfer aren't appropriately highlighted.
583"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584
Bram Moolenaaradc21822011-04-01 18:03:16 +0200585" ======================
586" Netrw Initialization: {{{1
587" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200588if 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 +0100589" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100590 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200591" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100592 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100593 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
594 au VimEnter * let s:initbeval= &beval
595"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100596" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
597" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
598" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
599" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
600" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
601" 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 +0200602endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200603au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200604
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200605if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100606 com! -nargs=* NetrwKeepj keepj <args>
607else
608 let g:netrw_keepj= ""
609 com! -nargs=* NetrwKeepj <args>
610endif
611
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000612" ==============================
613" Netrw Utility Functions: {{{1
614" ==============================
615
Bram Moolenaaradc21822011-04-01 18:03:16 +0200616" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100617" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100618if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100619" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100620 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100621 if &ft != "netrw"
622 return ""
623 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200624 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
625 " popup error window is still showing
626 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
627 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
628 " text under mouse hasn't changed; only close window when it changes
629 call popup_close(s:popuperr_id)
630 unlet s:popuperr_text
631 else
632 let s:popuperr_text= v:beval_text
633 endif
634 let mesg= ""
635 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 +0100636 let mesg= ""
637 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
638 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
639 elseif getline(v:beval_lnum) =~ '^"\s*/'
640 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
641 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100642 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100643 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
644 let mesg = "S: edit sorting sequence"
645 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
646 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
647 elseif v:beval_text == "Quick" || v:beval_text == "Help"
648 let mesg = "Help: press <F1>"
649 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
650 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
651 else
652 let mesg= ""
653 endif
654 return mesg
655 endfun
656"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100657" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
658" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
659" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
660" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
661" 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 +0200662endif
663
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200665" netrw#Explore: launch the local browser in the directory of the current file {{{2
666" indx: == -1: Nexplore
667" == -2: Pexplore
668" == +: this is overloaded:
669" * If Nexplore/Pexplore is in use, then this refers to the
670" indx'th item in the w:netrw_explore_list[] of items which
671" matched the */pattern **/pattern *//pattern **//pattern
672" * If Hexplore or Vexplore, then this will override
673" g:netrw_winsize to specify the qty of rows or columns the
674" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100675" 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 +0200676" dosplit==1: the window will be split before running the local browser
677" style == 0: Explore style == 1: Explore!
678" == 2: Hexplore style == 3: Hexplore!
679" == 4: Vexplore style == 5: Vexplore!
680" == 6: Texplore
681fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100682" 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 +0100683" 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 +0200684 if !exists("b:netrw_curdir")
685 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100686" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200687 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100688
689 " record current file for Rexplore's benefit
690 if &ft != "netrw"
691 let w:netrw_rexfile= expand("%:p")
692 endif
693
694 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200695 let curdir = simplify(b:netrw_curdir)
696 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200697 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200698 let curdir= substitute(curdir,'\','/','g')
699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100700" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100701
702 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
703 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
704 " try Explore again.
705 if a:0 > 0
706" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100707 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
708 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
709 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
710 \ '~'.expand("<slnum>"))
711 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200712 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
713 if a1 != a:1
714 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
715 return
716 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100717 endif
718 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200719
720 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200721 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100722" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100723 sil! let keepregstar = @*
724 sil! let keepregplus = @+
725 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200726 sil! let keepregslash= @/
727
Bram Moolenaar8d043172014-01-23 14:24:41 +0100728 " if dosplit
729 " -or- file has been modified AND file not hidden when abandoned
730 " -or- Texplore used
731 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 call s:SaveWinVars()
733 let winsz= g:netrw_winsize
734 if a:indx > 0
735 let winsz= a:indx
736 endif
737
738 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200739 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200740 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200741 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200742
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200743 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200745 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200746 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200747
748 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200749 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200750 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200751 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200754 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200755 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200756 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200757
758 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200759 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200760 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200761 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200762
763 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200764 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200765 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200766 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200767
768 elseif a:style == 6 " Texplore
769 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 exe "keepalt tabnew ".fnameescape(curdir)
771 call s:RestoreBufVars()
772 endif
773 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100775 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200776
777 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
786 if dirname !~ '/$'
787 let dirname= dirname."/"
788 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200794 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 let dirname= a:1
801 endif
802 else
803 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100804" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 call s:NetrwClearExplore()
806" call Dret("netrw#Explore : cleared list")
807 return
808 endif
809
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 if dirname =~ '\.\./\=$'
812 let dirname= simplify(fnamemodify(dirname,':p:h'))
813 elseif dirname =~ '\.\.' || dirname == '.'
814 let dirname= simplify(fnamemodify(dirname,':p'))
815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817
818 if dirname =~ '^\*//'
819 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
822 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
825
826 elseif dirname =~ '^\*\*//'
827 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 let pattern= substitute(dirname,'^\*\*//','','')
830 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832
833 elseif dirname =~ '/\*\*/'
834 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100835" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200837 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 let b:netrw_curdir = prefixdir
839 else
840 let b:netrw_curdir= getcwd().'/'.prefixdir
841 endif
842 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
843 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100844" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
845" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200846
847 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200848 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200849 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200851
852 elseif dirname=~ '^\*\*/'
853 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
854 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100855" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200856
857 else
858 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200860 endif
861
862 if starpat == 0 && a:indx >= 0
863 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100864" 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 +0200865 if dirname == ""
866 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200869 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200870 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200872 if dirname == ""
873 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200874 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100875 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100876 " depending on whether backslashes have been converted to forward slashes by earlier code).
877 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 let dirname= b:netrw_curdir."/".dirname
879 endif
880 elseif dirname !~ '^/'
881 let dirname= b:netrw_curdir."/".dirname
882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100883" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200884 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100885" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
886" 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 +0200887 endif
888 if exists("w:netrw_bannercnt")
889 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
890 " If one wants to return the same place in the netrw window, use :Rex instead.
891 exe w:netrw_bannercnt
892 endif
893
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100894" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200895 " ---------------------------------------------------------------------
896 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
897" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100898" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200899" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100900" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200901" endif
902 " ---------------------------------------------------------------------
903
904 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
905 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
906 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
907 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
908 elseif a:indx <= 0
909 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100910" 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 +0200911 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100912" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200913 let s:didstarstar= 1
914 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
915 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
916 endif
917
918 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100919" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 if !exists("w:netrw_explore_indx")
921 let w:netrw_explore_indx= 0
922 endif
923
924 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926
927 if indx == -1
928 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100929" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200930 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100931 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 +0200932 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100933" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100934 if @* != keepregstar | sil! let @* = keepregstar | endif
935 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100936 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200937 sil! let @/ = keepregslash
938" call Dret("netrw#Explore")
939 return
940 endif
941 let indx= w:netrw_explore_indx
942 if indx < 0 | let indx= 0 | endif
943 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
944 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100945" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
947 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 endwhile
950 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952
953 elseif indx == -2
954 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100957 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 +0200958 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100959" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100960 if @* != keepregstar | sil! let @* = keepregstar | endif
961 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100962 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200963 sil! let @/ = keepregslash
964" call Dret("netrw#Explore")
965 return
966 endif
967 let indx= w:netrw_explore_indx
968 if indx < 0 | let indx= 0 | endif
969 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
970 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100971" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 while indx >= 0 && curfile == w:netrw_explore_list[indx]
973 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 endwhile
976 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978
979 else
980 " Explore -- initialize
981 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100982" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100983 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 let w:netrw_explore_indx= 0
985 if !exists("b:netrw_curdir")
986 let b:netrw_curdir= getcwd()
987 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100988" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200989
990 " switch on starpat to build the w:netrw_explore_list of files
991 if starpat == 1
992 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100993" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
994" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200995 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100996 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200997 catch /^Vim\%((\a\+)\)\=:E480/
998 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
999" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1000 return
1001 endtry
1002 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1003 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1004
1005 elseif starpat == 2
1006 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001007" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1008" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001010 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001011 catch /^Vim\%((\a\+)\)\=:E480/
1012 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1013 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001014 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001015" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001016 if @* != keepregstar | sil! let @* = keepregstar | endif
1017 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001018 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 sil! let @/ = keepregslash
1020" call Dret("netrw#Explore : no files matched pattern")
1021 return
1022 endtry
1023 let s:netrw_curdir = b:netrw_curdir
1024 let w:netrw_explore_list = getqflist()
1025 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1026 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1027
1028 elseif starpat == 3
1029 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001030" 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 +02001031 let filepat= substitute(dirname,'^\*/','','')
1032 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1034" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1036 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1037
1038 elseif starpat == 4
1039 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001040" 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 +02001041 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1042 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1043 endif " switch on starpat to build w:netrw_explore_list
1044
1045 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001046" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1047" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001048
1049 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001050 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001051 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001052" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001053 if @* != keepregstar | sil! let @* = keepregstar | endif
1054 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001055 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001056 sil! let @/ = keepregslash
1057" call Dret("netrw#Explore : no files matched")
1058 return
1059 endif
1060 endif " if indx ... endif
1061
1062 " NetrwStatusLine support - for exploring support
1063 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001064" 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 +02001065
1066 " wrap the indx around, but issue a note
1067 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1070 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001071 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 endif
1073
1074 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001075" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 call netrw#LocalBrowseCheck(newdir)
1081 if !exists("w:netrw_liststyle")
1082 let w:netrw_liststyle= g:netrw_liststyle
1083 endif
1084 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001085 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001087 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 endif
1089 let w:netrw_explore_mtchcnt = indx + 1
1090 let w:netrw_explore_bufnr = bufnr("%")
1091 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001092 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001093" 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 +02001094
1095 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001096" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001097 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001098 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 +02001099 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001100 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001101" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001102 if @* != keepregstar | sil! let @* = keepregstar | endif
1103 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001104 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001105 sil! let @/ = keepregslash
1106" call Dret("netrw#Explore : missing +path_extra")
1107 return
1108 endif
1109
1110 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001111" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001112 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1113 sil! unlet w:netrw_treedict
1114 sil! unlet w:netrw_treetop
1115 endif
1116 let newdir= dirname
1117 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001118 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001119 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001120 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 endif
1122 endif
1123
1124 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001125" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1126" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001130 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 let s:explore_prvdir = b:netrw_curdir
1133 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001134 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if b:netrw_curdir !~ '/$'
1136 let dirlen= dirlen + 1
1137 endif
1138 let prvfname= ""
1139 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001140" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 if fname =~ '^'.b:netrw_curdir
1142 if s:explore_match == ""
1143 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1144 else
1145 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1146 endif
1147 elseif fname !~ '^/' && fname != prvfname
1148 if s:explore_match == ""
1149 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1150 else
1151 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1152 endif
1153 endif
1154 let prvfname= fname
1155 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001156" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001157 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1158 exe "2match netrwMarkFile /".s:explore_match."/"
1159 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001160 endif
1161 echo "<s-up>==Pexplore <s-down>==Nexplore"
1162 else
1163 2match none
1164 if exists("s:explore_match") | unlet s:explore_match | endif
1165 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001166" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001167 endif
1168
Bram Moolenaara6878372014-03-22 21:02:50 +01001169 " since Explore may be used to initialize netrw's browser,
1170 " there's no danger of a late FocusGained event on initialization.
1171 " Consequently, set s:netrw_events to 2.
1172 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001173 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001174" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001175 if @* != keepregstar | sil! let @* = keepregstar | endif
1176 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001177 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001178 sil! let @/ = keepregslash
1179" call Dret("netrw#Explore : @/<".@/.">")
1180endfun
1181
1182" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001183" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001184" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1185" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1186" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1187" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1188" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001190" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191 let curwin= winnr()
1192
Bram Moolenaara6878372014-03-22 21:02:50 +01001193 if a:0 > 0 && a:1 != ""
1194 " if a netrw window is already on the left-side of the tab
1195 " and a directory has been specified, explore with that
1196 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001197" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001199" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001200 exe "1wincmd w"
1201 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 exe "Explore ".fnameescape(a1)
1204 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001205 let s:lexplore_win= curwin
1206 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 unlet t:netrw_lexposn
1210 endif
1211" call Dret("netrw#Lexplore")
1212 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001213 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 exe curwin."wincmd w"
1215 else
1216 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001217" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001218 endif
1219
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001222 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 else
1225 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001228" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229
1230 if lexwinnr > 0
1231 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 exe lexwinnr."wincmd w"
1234 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001235 let t:netrw_lexposn = winsaveview()
1236" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001237" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001238 close
1239 if lexwinnr < curwin
1240 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001242 if lexwinnr != curwin
1243 exe curwin."wincmd w"
1244 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001246" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247
1248 else
1249 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001250" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 exe "1wincmd w"
1252 let keep_altv = g:netrw_altv
1253 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001254 if a:count != 0
1255 let netrw_winsize = g:netrw_winsize
1256 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001257 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001259" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 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 +02001261" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001264 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001266 elseif curfile =~ '^\a\{3,}://'
1267" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001268 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001270" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001271 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 endif
1273 if a:count != 0
1274 let g:netrw_winsize = netrw_winsize
1275 endif
1276 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001277 let g:netrw_altv = keep_altv
1278 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001279 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1280 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001281 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001282 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001283" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1284" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001285 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001286" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001287" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1288 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289 unlet t:netrw_lexposn
1290 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292
1293 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001294 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295 if a:rightside
1296 let g:netrw_chgwin= 1
1297 else
1298 let g:netrw_chgwin= 2
1299 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001300" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001301 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001302
Bram Moolenaar8d043172014-01-23 14:24:41 +01001303" call Dret("netrw#Lexplore")
1304endfun
1305
1306" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001307" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001308" supports :NetrwClean -- remove netrw from first directory on runtimepath
1309" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001310fun! netrw#Clean(sys)
1311" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001312
1313 if a:sys
1314 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1315 else
1316 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1317 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001318" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001319 let diddel= 0
1320 let diddir= ""
1321
1322 if choice == 1
1323 for dir in split(&rtp,',')
1324 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001325" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001326 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1327 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1328 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1329 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1330 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1331 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 +00001332 let diddir= dir
1333 let diddel= diddel + 1
1334 if !a:sys|break|endif
1335 endif
1336 endfor
1337 endif
1338
1339 echohl WarningMsg
1340 if diddel == 0
1341 echomsg "netrw is either not installed or not removable"
1342 elseif diddel == 1
1343 echomsg "removed one copy of netrw from <".diddir.">"
1344 else
1345 echomsg "removed ".diddel." copies of netrw"
1346 endif
1347 echohl None
1348
Bram Moolenaara6878372014-03-22 21:02:50 +01001349" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001350endfun
1351
Bram Moolenaar5c736222010-01-06 20:54:52 +01001352" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001353" netrw#MakeTgt: make a target out of the directory name provided {{{2
1354fun! netrw#MakeTgt(dname)
1355" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1356 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001357 let svpos = winsaveview()
1358" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001359 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1360" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001361 if s:netrwmftgt_islocal
1362 let netrwmftgt= simplify(a:dname)
1363 else
1364 let netrwmftgt= a:dname
1365 endif
1366 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1367 " re-selected target, so just clear it
1368 unlet s:netrwmftgt s:netrwmftgt_islocal
1369 else
1370 let s:netrwmftgt= netrwmftgt
1371 endif
1372 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001373 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001374 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001375" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1376 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001377" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001378endfun
1379
Bram Moolenaara6878372014-03-22 21:02:50 +01001380" ---------------------------------------------------------------------
1381" netrw#Obtain: {{{2
1382" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001383" islocal=0 obtain from remote source
1384" =1 obtain from local source
1385" fname : a filename or a list of filenames
1386" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001387fun! netrw#Obtain(islocal,fname,...)
1388" 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 +02001389 " NetrwStatusLine support - for obtaining support
1390
1391 if type(a:fname) == 1
1392 let fnamelist= [ a:fname ]
1393 elseif type(a:fname) == 3
1394 let fnamelist= a:fname
1395 else
1396 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 +01001397" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 return
1399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 if a:0 > 0
1402 let tgtdir= a:1
1403 else
1404 let tgtdir= getcwd()
1405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407
1408 if exists("b:netrw_islocal") && b:netrw_islocal
1409 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1412 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001413 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001417" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001418 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 if v:shell_error != 0
1420 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 +01001421" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 return
1423 endif
1424 endfor
1425 else
1426 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001427" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1428 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1429" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001430 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 if v:shell_error != 0
1432 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 +01001433" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 return
1435 endif
1436 endif
1437 elseif !exists("b:netrw_curdir")
1438 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1439 else
1440 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1441 endif
1442
1443 else
1444 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001445" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001446 if type(a:fname) == 1
1447 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1448 endif
1449 call s:NetrwMethod(b:netrw_curdir)
1450
1451 if b:netrw_method == 4
1452 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001453" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001454 if exists("g:netrw_port") && g:netrw_port != ""
1455 let useport= " ".g:netrw_scpport." ".g:netrw_port
1456 else
1457 let useport= ""
1458 endif
1459 if b:netrw_fname =~ '/'
1460 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1461 else
1462 let path= ""
1463 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001464 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001465 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 +02001466
1467 elseif b:netrw_method == 2
1468 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001470 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 let tmpbufnr= bufnr("%")
1472 setl ff=unix
1473 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001474 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 endif
1477
1478 if exists("b:netrw_fname") && b:netrw_fname != ""
1479 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001480" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 endif
1482
1483 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001484 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 endif
1487 for fname in fnamelist
1488 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 endfor
1491 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 endif
1496 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1497 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1498 let debugkeep= &debug
1499 setl debug=msg
1500 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1501 let &debug= debugkeep
1502 endif
1503
1504 elseif b:netrw_method == 3
1505 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001506" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001507 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001508 let tmpbufnr= bufnr("%")
1509 setl ff=unix
1510
1511 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001512 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001513" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 endif
1518
1519 if exists("g:netrw_uid") && g:netrw_uid != ""
1520 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001528 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 endif
1531 endif
1532
1533 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537
1538 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001539 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001540" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001541 endif
1542
1543 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 endif
1547
1548 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001549 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001550" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 endif
1552 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001553 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001555" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001556
1557 " perform ftp:
1558 " -i : turns off interactive prompting from ftp
1559 " -n unix : DON'T use <.netrc>, even though it exists
1560 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001561 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1562 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001563 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001564 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1565 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001566" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001568 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001569 endif
1570 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001571
1572 elseif b:netrw_method == 9
1573 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001574" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001575 if a:fname =~ '/'
1576 let localfile= substitute(a:fname,'^.*/','','')
1577 else
1578 let localfile= a:fname
1579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001580 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 +02001581
Bram Moolenaarff034192013-04-24 18:51:19 +02001582 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001583 " probably a badly formed url; protocol not recognized
1584" call Dret("netrw#Obtain : unsupported method")
1585 return
1586
1587 else
1588 " protocol recognized but not supported for Obtain (yet?)
1589 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001590 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001591 endif
1592" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001593 return
1594 endif
1595
1596 " restore status line
1597 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001598 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001599 endif
1600
1601 endif
1602
1603 " cleanup
1604 if exists("tmpbufnr")
1605 if bufnr("%") != tmpbufnr
1606 exe tmpbufnr."bw!"
1607 else
1608 q!
1609 endif
1610 endif
1611
Bram Moolenaara6878372014-03-22 21:02:50 +01001612" call Dret("netrw#Obtain")
1613endfun
1614
1615" ---------------------------------------------------------------------
1616" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1617fun! netrw#Nread(mode,fname)
1618" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001619 let svpos= winsaveview()
1620" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001621 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001622" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1623 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001624
1625 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1626 if exists("w:netrw_bannercnt")
1627 " start with cursor just after the banner
1628 exe w:netrw_bannercnt
1629 endif
1630 endif
1631" call Dret("netrw#Nread")
1632endfun
1633
1634" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001635" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1636" Options get restored by s:NetrwOptionsRestore()
1637"
1638" Option handling:
1639" * save user's options (s:NetrwOptionsSave)
1640" * set netrw-safe options (s:NetrwOptionsSafe)
1641" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1642" * restore user's options (s:netrwOPtionsRestore)
1643" - restore a user option when != safe option (s:NetrwRestoreSetting)
1644" vt: (variable type) normally its either "w:" or "s:"
1645fun! s:NetrwOptionsSave(vt)
1646" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1647" 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 +02001648" 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>"))
1649" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001650
1651 if !exists("{a:vt}netrw_optionsave")
1652 let {a:vt}netrw_optionsave= 1
1653 else
1654" call Dret("s:NetrwOptionsSave : options already saved")
1655 return
1656 endif
1657" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1658
1659 " Save current settings and current directory
1660" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1661 let s:yykeep = @@
1662 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1663 let {a:vt}netrw_aikeep = &l:ai
1664 let {a:vt}netrw_awkeep = &l:aw
1665 let {a:vt}netrw_bhkeep = &l:bh
1666 let {a:vt}netrw_blkeep = &l:bl
1667 let {a:vt}netrw_btkeep = &l:bt
1668 let {a:vt}netrw_bombkeep = &l:bomb
1669 let {a:vt}netrw_cedit = &cedit
1670 let {a:vt}netrw_cikeep = &l:ci
1671 let {a:vt}netrw_cinkeep = &l:cin
1672 let {a:vt}netrw_cinokeep = &l:cino
1673 let {a:vt}netrw_comkeep = &l:com
1674 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001675 let {a:vt}netrw_cuckeep = &l:cuc
1676 let {a:vt}netrw_culkeep = &l:cul
1677" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 let {a:vt}netrw_diffkeep = &l:diff
1679 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001680 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1681 let {a:vt}netrw_ffkeep = &l:ff
1682 endif
1683 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1684 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001685 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 let {a:vt}netrw_hidkeep = &l:hidden
1687 let {a:vt}netrw_imkeep = &l:im
1688 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001689 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001690 let {a:vt}netrw_lskeep = &l:ls
1691 let {a:vt}netrw_makeep = &l:ma
1692 let {a:vt}netrw_magickeep = &l:magic
1693 let {a:vt}netrw_modkeep = &l:mod
1694 let {a:vt}netrw_nukeep = &l:nu
1695 let {a:vt}netrw_rnukeep = &l:rnu
1696 let {a:vt}netrw_repkeep = &l:report
1697 let {a:vt}netrw_rokeep = &l:ro
1698 let {a:vt}netrw_selkeep = &l:sel
1699 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001700 if !g:netrw_use_noswf
1701 let {a:vt}netrw_swfkeep = &l:swf
1702 endif
1703 let {a:vt}netrw_tskeep = &l:ts
1704 let {a:vt}netrw_twkeep = &l:tw " textwidth
1705 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1706 let {a:vt}netrw_wrapkeep = &l:wrap
1707 let {a:vt}netrw_writekeep = &l:write
1708
1709 " save a few selected netrw-related variables
1710" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1711 if g:netrw_keepdir
1712 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001713" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001714 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001715 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001716 sil! let {a:vt}netrw_starkeep = @*
1717 sil! let {a:vt}netrw_pluskeep = @+
1718 endif
1719 sil! let {a:vt}netrw_slashkeep= @/
1720
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001721" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722" 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>"))
1723" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1724endfun
1725
1726" ---------------------------------------------------------------------
1727" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1728" Use s:NetrwSaveOptions() to save user settings
1729" Use s:NetrwOptionsRestore() to restore user settings
1730fun! s:NetrwOptionsSafe(islocal)
1731" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1732" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1733" 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>"))
1734 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1735 call s:NetrwSetSafeSetting("&l:ai",0)
1736 call s:NetrwSetSafeSetting("&l:aw",0)
1737 call s:NetrwSetSafeSetting("&l:bl",0)
1738 call s:NetrwSetSafeSetting("&l:bomb",0)
1739 if a:islocal
1740 call s:NetrwSetSafeSetting("&l:bt","nofile")
1741 else
1742 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1743 endif
1744 call s:NetrwSetSafeSetting("&l:ci",0)
1745 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001746 if g:netrw_fastbrowse > a:islocal
1747 call s:NetrwSetSafeSetting("&l:bh","hide")
1748 else
1749 call s:NetrwSetSafeSetting("&l:bh","delete")
1750 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001751 call s:NetrwSetSafeSetting("&l:cino","")
1752 call s:NetrwSetSafeSetting("&l:com","")
1753 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1754 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1755 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001756 if &go =~ 'a' | set go-=a | endif
1757 if &go =~ 'A' | set go-=A | endif
1758 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001759 call s:NetrwSetSafeSetting("&l:hid",0)
1760 call s:NetrwSetSafeSetting("&l:im",0)
1761 setl isk+=@ isk+=* isk+=/
1762 call s:NetrwSetSafeSetting("&l:magic",1)
1763 if g:netrw_use_noswf
1764 call s:NetrwSetSafeSetting("swf",0)
1765 endif
1766 call s:NetrwSetSafeSetting("&l:report",10000)
1767 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1768 call s:NetrwSetSafeSetting("&l:spell",0)
1769 call s:NetrwSetSafeSetting("&l:tw",0)
1770 call s:NetrwSetSafeSetting("&l:wig","")
1771 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001772
1773 " set up cuc and cul based on g:netrw_cursor and listing style
1774 " COMBAK -- cuc cul related
1775 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001776
1777 " allow the user to override safe options
1778" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1779 if &ft == "netrw"
1780" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1781 keepalt NetrwKeepj doau FileType netrw
1782 endif
1783
1784" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1785" 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>"))
1786" call Dret("s:NetrwOptionsSafe")
1787endfun
1788
1789" ---------------------------------------------------------------------
1790" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1791fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001792 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001793 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1794 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1795 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001796 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001797 else
1798 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001799 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001800 return
1801 endif
1802 unlet {a:vt}netrw_optionsave
1803
1804 if exists("+acd")
1805 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001806 let curdir = getcwd()
1807 let &l:acd = {a:vt}netrw_acdkeep
1808 unlet {a:vt}netrw_acdkeep
1809 if &l:acd
1810 call s:NetrwLcd(curdir)
1811 endif
1812 endif
1813 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001814 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1815 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1816 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1817 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1818 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1819 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1820 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1821 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1822 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1823 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1824 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1825 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1826 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1827 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1828 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001829 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001830 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1831 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001832 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1835 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001836 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001837 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1838 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001839 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1841 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001842 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1843 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1844 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1845 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001846 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001847 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1848 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1849 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001850 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1851 call s:NetrwRestoreSetting("s:yykeep","@@")
1852 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1853 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1854 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1855 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1856
Bram Moolenaara6878372014-03-22 21:02:50 +01001857 if exists("{a:vt}netrw_swfkeep")
1858 if &directory == ""
1859 " user hasn't specified a swapfile directory;
1860 " netrw will temporarily set the swapfile directory
1861 " to the current directory as returned by getcwd().
1862 let &l:directory= getcwd()
1863 sil! let &l:swf = {a:vt}netrw_swfkeep
1864 setl directory=
1865 unlet {a:vt}netrw_swfkeep
1866 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001867 if !g:netrw_use_noswf
1868 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1869 sil! let &l:swf= {a:vt}netrw_swfkeep
1870 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001871 unlet {a:vt}netrw_swfkeep
1872 endif
1873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001874 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001875 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1876 if exists("{a:vt}netrw_dirkeep")
1877 call s:NetrwLcd(dirkeep)
1878 unlet {a:vt}netrw_dirkeep
1879 endif
1880 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001881 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001882 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1883 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001884 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001885 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001886
Bram Moolenaara6878372014-03-22 21:02:50 +01001887 " Moved the filetype detect here from NetrwGetFile() because remote files
1888 " were having their filetype detect-generated settings overwritten by
1889 " NetrwOptionRestore.
1890 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001891 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001892 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001893endfun
1894
1895" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001896" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1897" but only when the options' value and the safe setting differ
1898" Doing this means that netrw will not come up as having changed a
1899" setting last when it really didn't actually change it.
1900"
1901" Called from s:NetrwOptionsSafe
1902" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1903fun! s:NetrwSetSafeSetting(setting,safesetting)
1904" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001905
Bram Moolenaar85850f32019-07-19 22:05:51 +02001906 if a:setting =~ '^&'
1907" call Decho("fyi: a:setting starts with &")
1908 exe "let settingval= ".a:setting
1909" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001910
Bram Moolenaar85850f32019-07-19 22:05:51 +02001911 if settingval != a:safesetting
1912" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1913 if type(a:safesetting) == 0
1914 exe "let ".a:setting."=".a:safesetting
1915 elseif type(a:safesetting) == 1
1916 exe "let ".a:setting."= '".a:safesetting."'"
1917 else
1918 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1919 endif
1920 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001921 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001922
Bram Moolenaar85850f32019-07-19 22:05:51 +02001923" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001924endfun
1925
1926" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001927" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1928" but only if the setting value differs from the associated keepvar.
1929" Doing this means that netrw will not come up as having changed a
1930" setting last when it really didn't actually change it.
1931"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001932" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001933" keepvars are set up by s:NetrwOptionsSave
1934fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001935""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001936
Bram Moolenaar85850f32019-07-19 22:05:51 +02001937 " typically called from s:NetrwOptionsRestore
1938 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1939 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001940 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001941 if exists(a:keepvar)
1942 exe "let keepvarval= ".a:keepvar
1943 exe "let setting= ".a:setting
1944
1945"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1946"" call Decho("fyi: keepvarval=".keepvarval)
1947"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1948
1949 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001950"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001951 if type(a:setting) == 0
1952 exe "let ".a:setting."= ".keepvarval
1953 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001954 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001955 else
1956 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1957 endif
1958 endif
1959
1960 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001961 endif
1962
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001964endfun
1965
1966" ---------------------------------------------------------------------
1967" NetrwStatusLine: {{{2
1968fun! NetrwStatusLine()
1969
1970" vvv NetrwStatusLine() debugging vvv
1971" let g:stlmsg=""
1972" if !exists("w:netrw_explore_bufnr")
1973" let g:stlmsg="!X<explore_bufnr>"
1974" elseif w:netrw_explore_bufnr != bufnr("%")
1975" let g:stlmsg="explore_bufnr!=".bufnr("%")
1976" endif
1977" if !exists("w:netrw_explore_line")
1978" let g:stlmsg=" !X<explore_line>"
1979" elseif w:netrw_explore_line != line(".")
1980" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1981" endif
1982" if !exists("w:netrw_explore_list")
1983" let g:stlmsg=" !X<explore_list>"
1984" endif
1985" ^^^ NetrwStatusLine() debugging ^^^
1986
1987 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")
1988 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001989 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001990 let &laststatus = s:netrw_users_ls
1991 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1992 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1993 return ""
1994 else
1995 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1996 endif
1997endfun
1998
Bram Moolenaar85850f32019-07-19 22:05:51 +02001999" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002000" Netrw Transfer Functions: {{{1
2001" ===============================
2002
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002004" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002005" mode: =0 read remote file and insert before current line
2006" =1 read remote file and insert after current line
2007" =2 replace with remote file
2008" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002009fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002010" 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 +00002011
Bram Moolenaar5c736222010-01-06 20:54:52 +01002012 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002013 call s:NetrwOptionsSave("w:")
2014 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002015 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002016 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2017 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2018 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002019" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002020
Bram Moolenaar5c736222010-01-06 20:54:52 +01002021 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002022 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002023 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002024 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002025 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002026 elseif a:mode == 2 " replace with remote file
2027 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002028 elseif a:mode == 3 " skip read of file (leave as temporary)
2029 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002030 else
2031 exe a:mode
2032 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002033 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002034 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002035" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002036
Bram Moolenaar5c736222010-01-06 20:54:52 +01002037 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002038 let tmpfile= s:GetTempfile("")
2039 if tmpfile == ""
2040" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002041 return
2042 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002044 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002046 " attempt to repeat with previous host-file-etc
2047 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002048" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002049 let choice = b:netrw_lastfile
2050 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 else
2053 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002054" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002057 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002058 echomsg 'NetRead Usage:'
2059 echomsg ':Nread machine:path uses rcp'
2060 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2061 echomsg ':Nread "machine id password path" uses ftp'
2062 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2063 echomsg ':Nread fetch://machine/path uses fetch'
2064 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2065 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002066 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002067 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002068 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2069 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2070 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2071 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002072 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002074
Bram Moolenaar9964e462007-05-05 17:54:07 +00002075 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002076 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002077" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002078 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002080 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 else
2082 " case "... ... ..."
2083 let choice = strpart(choice,1,strlen(choice)-1)
2084 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002085
Bram Moolenaar9964e462007-05-05 17:54:07 +00002086 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002087 let wholechoice = wholechoice . " " . choice
2088 let ichoice = ichoice + 1
2089 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002090 if !exists("g:netrw_quiet")
2091 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2092 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002093" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 return
2095 endif
2096 let choice= a:{ichoice}
2097 endwhile
2098 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2099 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 endif
2101 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002103" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002105
Bram Moolenaar5c736222010-01-06 20:54:52 +01002106 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002107 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002108 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002109" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002110 return
2111 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113
Bram Moolenaar8d043172014-01-23 14:24:41 +01002114 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002115" 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 +02002116 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002117" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002118 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002119" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002122
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002124 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002125 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002126 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2127 echo "(netrw) Processing your read request..."
2128 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002129
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002131 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002132 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002133" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002134 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002135 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002136 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 " ER: the tmpfile is full path: rcp sees C:\... as host C
2138 if s:netrw_has_nt_rcp == 1
2139 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2140 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2141 else
2142 " Any way needed it machine contains a '.'
2143 let uid_machine = g:netrw_machine .'.'. $USERNAME
2144 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002146 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2147 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2148 else
2149 let uid_machine = g:netrw_machine
2150 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002152 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 +00002153 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002159" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002160 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002161 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002162 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002163 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002164 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002165" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002166 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002167 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002168" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002169 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002170 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002171" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002173 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 +00002174 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002175 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 endif
2177 " 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 +00002178 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002179 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002180 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002182 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002184 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002186 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2187 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002188 q!
2189 endif
2190 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002191 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002193
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002195 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2197 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002199 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002201 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002202 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002204 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002207 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002210
Bram Moolenaar97d62492012-11-15 21:28:22 +01002211 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002212 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002213 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002214" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002215 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002216 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002217 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002219 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002220 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002222 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002226 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002227" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002229 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002230 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002232 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 " perform ftp:
2237 " -i : turns off interactive prompting from ftp
2238 " -n unix : DON'T use <.netrc>, even though it exists
2239 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002240 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2243 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002245 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002246 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002247 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002249 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002250 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002252
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002254 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002258 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 else
2260 let useport= ""
2261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2263 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002264 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002265 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2266 else
2267 let tmpfile_get = tmpfile
2268 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002269 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 +00002270 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002274 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002275 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002279 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002280 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002281" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002282 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002284
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002285 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2286 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002287" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002288 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289 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 +00002290 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002291 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 +00002292 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002293 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002294
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002296 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002297" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002298 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2299 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002300" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2301" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2302 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 +00002303 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002304" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002305 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 endif
2307 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002309 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002310
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002312 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002313 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaar5c736222010-01-06 20:54:52 +01002316 if !executable(g:netrw_dav_cmd)
2317 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2318" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2319 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002320 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002321 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322 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 +01002323 else
2324 " Construct execution string (four lines) which will be passed through filter
2325 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2326 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002327 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002328 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002329 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002330 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002331 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002332 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002333 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002334 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002335 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002336 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2337 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002338
Bram Moolenaar5c736222010-01-06 20:54:52 +01002339 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002340 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002341 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002343 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002344 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002349 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002351 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 +00002352 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002353 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002354
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002355 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002357 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002358 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002359" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002360 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002361 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002363 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002364" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002365 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002366 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002367 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 let netrw_option= "http"
2369 else
2370 let netrw_option= "ftp"
2371 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002372" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002373
Bram Moolenaar446cb832008-06-24 21:56:24 +00002374 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375 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 +00002376 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002377 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 +00002378 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaar446cb832008-06-24 21:56:24 +00002380 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002382" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002383 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002384
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002386 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002387 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002388" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2389 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 +00002390 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002392
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002394 " NetRead: (file) NetRead Method #10 {{{3
2395 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002396" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2397 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002398 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2399 let b:netrw_lastfile = choice
2400
2401 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002402 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002403 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002404 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 endif
2406 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002407
Bram Moolenaar5c736222010-01-06 20:54:52 +01002408 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002409 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 unlet b:netrw_fname
2413 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002414 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 +01002415" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002416 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002417 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002418 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002419
Bram Moolenaar9964e462007-05-05 17:54:07 +00002420" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421endfun
2422
2423" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002424" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002425fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002426" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002427
Bram Moolenaar5c736222010-01-06 20:54:52 +01002428 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002430 call s:NetrwOptionsSave("w:")
2431 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002432
Bram Moolenaar5c736222010-01-06 20:54:52 +01002433 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002434 let tmpfile= s:GetTempfile("")
2435 if tmpfile == ""
2436" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002437 return
2438 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002439
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 if a:0 == 0
2441 let ichoice = 0
2442 else
2443 let ichoice = 1
2444 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002445
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002447" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002448 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002449 " For binary writes, always write entire file.
2450 " (line numbers don't really make sense for that).
2451 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002452" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002453 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454 elseif g:netrw_cygwin
2455 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002456 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002457" 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 +01002458 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002459 else
2460 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002461" 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 +01002462 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002463 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaar9964e462007-05-05 17:54:07 +00002465 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002466 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002467 " on the temporary file's name. Deletion of the temporary file during
2468 " cleanup then causes an error message.
2469 0file!
2470 endif
2471
Bram Moolenaar5c736222010-01-06 20:54:52 +01002472 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002473 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002474
Bram Moolenaar9964e462007-05-05 17:54:07 +00002475 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002476 " attempt to repeat with previous host-file-etc
2477 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002478" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002479 let choice = b:netrw_lastfile
2480 let ichoice= ichoice + 1
2481 else
2482 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002483
Bram Moolenaar8d043172014-01-23 14:24:41 +01002484 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002485 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002486 echomsg 'NetWrite Usage:"'
2487 echomsg ':Nwrite machine:path uses rcp'
2488 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2489 echomsg ':Nwrite "machine id password path" uses ftp'
2490 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2491 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2492 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2493 echomsg ':Nwrite rcp://machine/path uses rcp'
2494 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2495 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2496 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002497 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002498 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002499
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002500 elseif match(choice,"^\"") != -1
2501 if match(choice,"\"$") != -1
2502 " case "..."
2503 let choice=strpart(choice,1,strlen(choice)-2)
2504 else
2505 " case "... ... ..."
2506 let choice = strpart(choice,1,strlen(choice)-1)
2507 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002508
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 while match(choice,"\"$") == -1
2510 let wholechoice= wholechoice . " " . choice
2511 let ichoice = ichoice + 1
2512 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002513 if !exists("g:netrw_quiet")
2514 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2515 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002516" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002517 return
2518 endif
2519 let choice= a:{ichoice}
2520 endwhile
2521 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2522 endif
2523 endif
2524 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002526" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002527
Bram Moolenaar9964e462007-05-05 17:54:07 +00002528 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002529 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002530 if !exists("b:netrw_method") || b:netrw_method < 0
2531" call Dfunc("netrw#NetWrite : unsupported method")
2532 return
2533 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002534
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002535 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002536 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002537 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002538 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2539 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002540" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002541 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002542
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002543 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002544 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002545 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002546" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002547 if s:netrw_has_nt_rcp == 1
2548 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2549 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2550 else
2551 let uid_machine = g:netrw_machine .'.'. $USERNAME
2552 endif
2553 else
2554 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2555 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2556 else
2557 let uid_machine = g:netrw_machine
2558 endif
2559 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002560 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 +00002561 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002562
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002563 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002565 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002566" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 let netrw_fname = b:netrw_fname
2568
2569 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2570 let bhkeep = &l:bh
2571 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002572 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002573 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002574
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002575" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002576 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002577 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002578" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002579 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002580 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002581" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002582 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002583 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002584" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002586 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 +00002587 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002588" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2589 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 endif
2591 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2592 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002593 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002594 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002595 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598
2599 " remove enew buffer (quietly)
2600 let filtbuf= bufnr("%")
2601 exe curbuf."b!"
2602 let &l:bh = bhkeep
2603 exe filtbuf."bw!"
2604
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002606
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002607 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002608 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002609 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002610 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002612 let netrw_fname = b:netrw_fname
2613 let bhkeep = &l:bh
2614
2615 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2616 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002617 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002619 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002620
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002621 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002622 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002623" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002624 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002625 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002626" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002628 if exists("g:netrw_uid") && g:netrw_uid != ""
2629 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002630 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002631" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002632 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002633 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002634 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002635" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002636 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002637 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002639 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002640 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002641 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002642" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002644 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002645" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002647 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002648" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 " save choice/id/password for future use
2650 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002651
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 " perform ftp:
2653 " -i : turns off interactive prompting from ftp
2654 " -n unix : DON'T use <.netrc>, even though it exists
2655 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002656 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2659 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002660 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002661 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002662 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 let mod=1
2664 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002665
2666 " remove enew buffer (quietly)
2667 let filtbuf= bufnr("%")
2668 exe curbuf."b!"
2669 let &l:bh= bhkeep
2670 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002671
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002674 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002677 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 else
2679 let useport= ""
2680 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681 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 +00002682 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002683
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002685 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002687" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002688 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2689 if executable(curl)
2690 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002691 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 +01002692 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002693 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002694 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002695
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002697 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002698 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002699" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002700
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002702 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2703 let bhkeep = &l:bh
2704
2705 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2706 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002707 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002709
Bram Moolenaarff034192013-04-24 18:51:19 +02002710 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002712 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002714 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002716 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002717 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002718 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002719 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002720
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002721 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002722 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002723 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002724
2725 " remove enew buffer (quietly)
2726 let filtbuf= bufnr("%")
2727 exe curbuf."b!"
2728 let &l:bh = bhkeep
2729 exe filtbuf."bw!"
2730
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002731 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002732
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002735 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002736" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002737 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 +00002738 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002739
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002741 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002742 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002743" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002744 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2746 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2747 else
2748 let uid_machine = g:netrw_machine
2749 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002750
2751 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2752 let bhkeep = &l:bh
2753 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002754 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002755 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002756
Bram Moolenaarff034192013-04-24 18:51:19 +02002757 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002758 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002759" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002760 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002761 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002762 let filtbuf= bufnr("%")
2763 exe curbuf."b!"
2764 let &l:bh = bhkeep
2765 exe filtbuf."bw!"
2766 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002767
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002768 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002769 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002770 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002771 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002772 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002774 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002775
Bram Moolenaar5c736222010-01-06 20:54:52 +01002776 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002777" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002778 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002780 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002781 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002782 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002783
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002784 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002785 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002786 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787" 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 +02002788 elseif !exists("leavemod")
2789 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002790" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002791 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792" 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 +00002793 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002794
Bram Moolenaar9964e462007-05-05 17:54:07 +00002795" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002796endfun
2797
2798" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002799" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002800" uses NetRead to get a copy of the file into a temporarily file,
2801" then sources that file,
2802" then removes that file.
2803fun! netrw#NetSource(...)
2804" call Dfunc("netrw#NetSource() a:0=".a:0)
2805 if a:0 > 0 && a:1 == '?'
2806 " give help
2807 echomsg 'NetSource Usage:'
2808 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2809 echomsg ':Nsource fetch://machine/path uses fetch'
2810 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002811 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2813 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2814 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2815 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2816 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002817 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002822 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002824 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002826 if delete(s:netrw_tmpfile)
2827 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2828 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829 unlet s:netrw_tmpfile
2830 else
2831 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2832 endif
2833 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002834 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002835 endif
2836" call Dret("netrw#NetSource")
2837endfun
2838
Bram Moolenaar8d043172014-01-23 14:24:41 +01002839" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002840" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2841" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002842fun! netrw#SetTreetop(iscmd,...)
2843" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2844" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002845
Bram Moolenaar85850f32019-07-19 22:05:51 +02002846 " iscmd==0: netrw#SetTreetop called using gn mapping
2847 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2848" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002849 " clear out the current tree
2850 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002852 let inittreetop= w:netrw_treetop
2853 unlet w:netrw_treetop
2854 endif
2855 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002857 unlet w:netrw_treedict
2858 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002859" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002860
Bram Moolenaar85850f32019-07-19 22:05:51 +02002861 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002862 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002863" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002864 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002865 if isdirectory(s:NetrwFile(a:1))
2866" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002867 let treedir = a:1
2868 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002869 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002870 let treedir = b:netrw_curdir."/".a:1
2871 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002872" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002873 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002874 " normally the cursor is left in the message window.
2875 " However, here this results in the directory being listed in the message window, which is not wanted.
2876 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002878 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002879 let treedir = "."
2880 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002881 endif
2882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002884
2885 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002886 let islocal= expand("%") !~ '^\a\{3,}://'
2887" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002888
2889 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002890 if islocal
2891 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2892 else
2893 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2894 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895
Bram Moolenaara6878372014-03-22 21:02:50 +01002896" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897endfun
2898
Bram Moolenaar9964e462007-05-05 17:54:07 +00002899" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002900" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002901" readcmd == %r : replace buffer with newly read file
2902" == 0r : read file at top of buffer
2903" == r : read file after current line
2904" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002905fun! s:NetrwGetFile(readcmd, tfile, method)
2906" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002907
2908 " readcmd=='t': simply do nothing
2909 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910" 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 +01002911" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002912 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002913 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002914
Bram Moolenaar9964e462007-05-05 17:54:07 +00002915 " get name of remote filename (ie. url and all)
2916 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002918
Bram Moolenaar9964e462007-05-05 17:54:07 +00002919 if exists("*NetReadFixup")
2920 " for the use of NetReadFixup (not otherwise used internally)
2921 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002922 endif
2923
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924 if a:readcmd[0] == '%'
2925 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002926" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927
2928 " rename the current buffer to the temp file (ie. tfile)
2929 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002930 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002931 else
2932 let tfile= a:tfile
2933 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002934 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935
2936 " edit temporary file (ie. read the temporary file in)
2937 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002938" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939 call zip#Browse(tfile)
2940 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002941" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002942 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002943 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002944" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002945 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002946 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002947" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002949 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002951 call tar#Browse(tfile)
2952 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002954 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002956" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002957 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958 endif
2959
2960 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002961 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002962
Bram Moolenaar71badf92023-04-22 22:40:14 +01002963 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002964 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002965 " Note that isk must not include a "/" for scripts.vim
2966 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002967" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2968" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002969" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002970" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2971 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002972 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002973 filetype detect
2974" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002975 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002976" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002977 let line1 = 1
2978 let line2 = line("$")
2979
Bram Moolenaar8d043172014-01-23 14:24:41 +01002980 elseif !&ma
2981 " 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 +01002982 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002984 return
2985
Bram Moolenaar9964e462007-05-05 17:54:07 +00002986 elseif s:FileReadable(a:tfile)
2987 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002988" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989 let curline = line(".")
2990 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002991" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002992 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002993 let line1= curline + 1
2994 let line2= line("$") - lastline + 1
2995
2996 else
2997 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002998" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2999" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003000 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003001" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003002 return
3003 endif
3004
3005 " User-provided (ie. optional) fix-it-up command
3006 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003007" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003008 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003009" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003011 endif
3012
Bram Moolenaaradc21822011-04-01 18:03:16 +02003013 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003014 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003015 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003016 endif
3017
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" 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 +00003019
3020 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003021" redraw!
3022
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003023" 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 +00003024" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003025endfun
3026
Bram Moolenaar9964e462007-05-05 17:54:07 +00003027" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003028" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003029" Input:
3030" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3031" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003032" b:netrw_method= 1: rcp
3033" 2: ftp + <.netrc>
3034" 3: ftp + machine, id, password, and [path]filename
3035" 4: scp
3036" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003037" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" 7: rsync
3039" 8: fetch
3040" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003041" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003042" g:netrw_machine= hostname
3043" b:netrw_fname = filename
3044" g:netrw_port = optional port number (for ftp)
3045" g:netrw_choice = copy of input url (choice)
3046fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003047" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003048
Bram Moolenaar251e1912011-06-19 05:09:16 +02003049 " sanity check: choice should have at least three slashes in it
3050 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3051 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3052 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003053" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003054 return
3055 endif
3056
Bram Moolenaar5c736222010-01-06 20:54:52 +01003057 " record current g:netrw_machine, if any
3058 " curmachine used if protocol == ftp and no .netrc
3059 if exists("g:netrw_machine")
3060 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003061" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003062 else
3063 let curmachine= "N O T A HOST"
3064 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003065 if exists("g:netrw_port")
3066 let netrw_port= g:netrw_port
3067 endif
3068
3069 " insure that netrw_ftp_cmd starts off every method determination
3070 " with the current g:netrw_ftp_cmd
3071 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003073 " initialization
3074 let b:netrw_method = 0
3075 let g:netrw_machine = ""
3076 let b:netrw_fname = ""
3077 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003078 let g:netrw_choice = a:choice
3079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003080 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003081 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003082 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3083 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003084 " rcpurm : rcp://[user@]host/filename Use rcp
3085 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003086 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003087 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003088 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003089 " rsyncurm : rsync://host[:port]/path Use rsync
3090 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3091 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003092 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003093 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3094 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003095 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3096 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003097 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003098 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003099 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003100 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003101 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003102 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003104 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003105
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003106" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003108 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003110" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003111 let b:netrw_method = 1
3112 let userid = substitute(a:choice,rcpurm,'\1',"")
3113 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3114 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 if userid != ""
3116 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003118
Bram Moolenaaradc21822011-04-01 18:03:16 +02003119 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003121" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003122 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003123 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3124 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3125 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003126
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003129" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let b:netrw_method = 5
3131 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3132 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003133 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003134
Bram Moolenaaradc21822011-04-01 18:03:16 +02003135 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003139 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003140 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3141 else
3142 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3143 endif
3144 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003145
Bram Moolenaaradc21822011-04-01 18:03:16 +02003146 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003148" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 let b:netrw_method = 7
3150 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3151 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003152
Bram Moolenaaradc21822011-04-01 18:03:16 +02003153 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003154 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003156 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3158 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3159 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003160" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 if userid != ""
3162 let g:netrw_uid= userid
3163 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003164
Bram Moolenaaradc21822011-04-01 18:03:16 +02003165 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003166 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003167 call NetUserPass("ftp:".g:netrw_machine)
3168 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003169 " if there's a change in hostname, require password re-entry
3170 unlet s:netrw_passwd
3171 endif
3172 if exists("netrw_port")
3173 unlet netrw_port
3174 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003175 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003176
Bram Moolenaar446cb832008-06-24 21:56:24 +00003177 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method = 3
3179 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003180 let host= substitute(g:netrw_machine,'\..*$','','')
3181 if exists("s:netrw_hup[host]")
3182 call NetUserPass("ftp:".host)
3183
Nir Lichtman1e34b952024-05-08 19:19:34 +02003184 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003185" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3186" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003187 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003188 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003190 endif
3191 let b:netrw_method= 2
3192 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003193" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 let b:netrw_method= 2
3195 else
3196 if !exists("g:netrw_uid") || g:netrw_uid == ""
3197 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003198 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003199 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003200 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003201 endif
3202 let b:netrw_method= 3
3203 endif
3204 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003205
Bram Moolenaaradc21822011-04-01 18:03:16 +02003206 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003207 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003208" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003209 let b:netrw_method = 8
3210 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3211 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3212 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3213 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003214
Bram Moolenaaradc21822011-04-01 18:03:16 +02003215 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003216 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003219 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3220 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003221 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003222 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003223 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003224
Bram Moolenaaradc21822011-04-01 18:03:16 +02003225 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003227" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003228 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003229 let b:netrw_method = 3
3230 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3231 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003232
Bram Moolenaar9964e462007-05-05 17:54:07 +00003233 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 let b:netrw_method = 2
3235 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3236 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaaradc21822011-04-01 18:03:16 +02003239 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 let b:netrw_method = 9
3243 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3244 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003245
Bram Moolenaaradc21822011-04-01 18:03:16 +02003246 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003248" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003249 let b:netrw_method = 1
3250 let userid = substitute(a:choice,rcphf,'\2',"")
3251 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3252 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003253" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3254" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3255" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3256" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 if userid != ""
3258 let g:netrw_uid= userid
3259 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003261 " Method#10: file://user@hostname/...path-to-file {{{3
3262 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003264 let b:netrw_method = 10
3265 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003266" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003267
Bram Moolenaaradc21822011-04-01 18:03:16 +02003268 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003269 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003270 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003271 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003272 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003275 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003276
Bram Moolenaar81695252004-12-29 20:58:21 +00003277 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003278 " remove any leading [:#] from port number
3279 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3280 elseif exists("netrw_port")
3281 " retain port number as implicit for subsequent ftp operations
3282 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003283 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003284
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3286" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3287" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3288" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003289" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003290" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003291" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003292" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003293" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003294" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003295" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003296" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298
Bram Moolenaar9964e462007-05-05 17:54:07 +00003299" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003300" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003301" Usage: :call NetUserPass() -- will prompt for userid and password
3302" :call NetUserPass("uid") -- will prompt for password
3303" :call NetUserPass("uid","password") -- sets global userid and password
3304" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3305" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306fun! NetUserPass(...)
3307
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003308" call Dfunc("NetUserPass() a:0=".a:0)
3309
3310 if !exists('s:netrw_hup')
3311 let s:netrw_hup= {}
3312 endif
3313
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003315 " case: no input arguments
3316
3317 " change host and username if not previously entered; get new password
3318 if !exists("g:netrw_machine")
3319 let g:netrw_machine= input('Enter hostname: ')
3320 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003322 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323 let g:netrw_uid= input('Enter username: ')
3324 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003325 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003326 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003327
3328 " set up hup database
3329 let host = substitute(g:netrw_machine,'\..*$','','')
3330 if !exists('s:netrw_hup[host]')
3331 let s:netrw_hup[host]= {}
3332 endif
3333 let s:netrw_hup[host].uid = g:netrw_uid
3334 let s:netrw_hup[host].passwd = s:netrw_passwd
3335
3336 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003337 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003338
3339 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003340 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003341 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003342" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003343 let host = substitute(a:1,'^ftp:','','')
3344 let host = substitute(host,'\..*','','')
3345 if exists("s:netrw_hup[host]")
3346 let g:netrw_uid = s:netrw_hup[host].uid
3347 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003348" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3349" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003350 else
3351 let g:netrw_uid = input("Enter UserId: ")
3352 let s:netrw_passwd = inputsecret("Enter Password: ")
3353 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003354
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003356 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003357" 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 +02003358 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003359 if g:netrw_machine =~ '[0-9.]\+'
3360 let host= g:netrw_machine
3361 else
3362 let host= substitute(g:netrw_machine,'\..*$','','')
3363 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003364 else
3365 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003366 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003367 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003368" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003369 if exists("g:netrw_passwd")
3370 " ask for password if one not previously entered
3371 let s:netrw_passwd= g:netrw_passwd
3372 else
3373 let s:netrw_passwd = inputsecret("Enter Password: ")
3374 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003375 endif
3376
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003377" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003378 if exists("host")
3379 if !exists('s:netrw_hup[host]')
3380 let s:netrw_hup[host]= {}
3381 endif
3382 let s:netrw_hup[host].uid = g:netrw_uid
3383 let s:netrw_hup[host].passwd = s:netrw_passwd
3384 endif
3385
3386 elseif a:0 == 2
3387 let g:netrw_uid = a:1
3388 let s:netrw_passwd = a:2
3389
3390 elseif a:0 == 3
3391 " enter hostname, user-id, and password into the hup dictionary
3392 let host = substitute(a:1,'^\a\+:','','')
3393 let host = substitute(host,'\..*$','','')
3394 if !exists('s:netrw_hup[host]')
3395 let s:netrw_hup[host]= {}
3396 endif
3397 let s:netrw_hup[host].uid = a:2
3398 let s:netrw_hup[host].passwd = a:3
3399 let g:netrw_uid = s:netrw_hup[host].uid
3400 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003401" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3402" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003404
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003405" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407
Bram Moolenaar85850f32019-07-19 22:05:51 +02003408" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003409" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003410" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003412" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003413" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3414fun! s:ExplorePatHls(pattern)
3415" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3416 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003417" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003418 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003419" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003420 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3421" call Dret("s:ExplorePatHls repat<".repat.">")
3422 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003423endfun
3424
3425" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003426" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003427" 0: (user: <mb>) bookmark current directory
3428" 1: (user: <gb>) change to the bookmarked directory
3429" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003430" 3: (browsing) records current directory history
3431" 4: (user: <u>) go up (previous) directory, using history
3432" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003433" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003434fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003435" 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 +02003436 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3437" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3438 return
3439 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003440
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003441 let ykeep = @@
3442 let curbufnr = bufnr("%")
3443
Bram Moolenaar9964e462007-05-05 17:54:07 +00003444 if a:chg == 0
3445 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003447 if exists("s:netrwmarkfilelist_{curbufnr}")
3448 call s:NetrwBookmark(0)
3449 echo "bookmarked marked files"
3450 else
3451 call s:MakeBookmark(a:curdir)
3452 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003453 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003454
KSR-Yasudaf4498252023-10-06 03:34:17 +09003455 try
3456 call s:NetrwBookHistSave()
3457 catch
3458 endtry
3459
Bram Moolenaar9964e462007-05-05 17:54:07 +00003460 elseif a:chg == 1
3461 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003462" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003463 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003464" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003465 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003466 else
3467 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3468 endif
3469
3470 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003471" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003472 let didwork= 0
3473 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003474" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003475 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003476" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003477 let cnt= 1
3478 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003479" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003480 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003481 let didwork = 1
3482 let cnt = cnt + 1
3483 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003484 endif
3485
3486 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003487 " Note: history is saved only when PerformListing is done;
3488 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3489 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490 let first = 1
3491 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003492 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003493 while ( first || cnt != g:netrw_dirhistcnt )
3494" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003495 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003496" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003497 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003498 let didwork= 1
3499 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003500 let histcnt = histcnt + 1
3501 let first = 0
3502 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003503 if cnt < 0
3504 let cnt= cnt + g:netrw_dirhistmax
3505 endif
3506 endwhile
3507 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003508 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003509 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003510 if didwork
3511 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3512 endif
3513
3514 elseif a:chg == 3
3515 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003516" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003517 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 +02003518 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003519 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3520 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003522" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003523 endif
3524
3525 elseif a:chg == 4
3526 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003527" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3530 if g:netrw_dirhistcnt < 0
3531 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003532 endif
3533 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003534 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003535 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003536 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3537" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003539 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003540" call Decho("setl ma noro",'~'.expand("<slnum>"))
3541 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003542 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543" call Decho("setl nomod",'~'.expand("<slnum>"))
3544" 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 +00003545 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3547 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003548 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003549 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003553 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003554 echo "Sorry, no predecessor directory exists yet"
3555 endif
3556
3557 elseif a:chg == 5
3558 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003559" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3562 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3563" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003565" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003566 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003567 sil! NetrwKeepj %d _
3568" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3569" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003570 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003571" 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 +02003572 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003573" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3574 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003575 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3577 if g:netrw_dirhistcnt < 0
3578 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003579 endif
3580 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003581 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003582 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003585 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003586
3587 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003588" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003589 if exists("s:netrwmarkfilelist_{curbufnr}")
3590 call s:NetrwBookmark(1)
3591 echo "removed marked files from bookmarks"
3592 else
3593 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003594 let iremove = v:count
3595 let dremove = g:netrw_bookmarklist[iremove - 1]
3596" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003597 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3599 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3600 echo "removed ".dremove." from g:netrw_bookmarklist"
3601" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003602 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003603" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003604
3605 try
3606 call s:NetrwBookHistSave()
3607 catch
3608 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003609 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003610 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003611 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003612 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003613" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003614endfun
3615
3616" ---------------------------------------------------------------------
3617" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003618" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003619" Sister function: s:NetrwBookHistSave()
3620fun! s:NetrwBookHistRead()
3621" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003622 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003623" 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 +02003624 return
3625 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003626 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003627
3628 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003629 if !exists("s:netrw_initbookhist")
3630 let home = s:NetrwHome()
3631 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003632 if filereadable(s:NetrwFile(savefile))
3633" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003634 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003635 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003636
3637 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003638 if g:netrw_dirhistmax > 0
3639 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003640 if filereadable(s:NetrwFile(savefile))
3641" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003642 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003643 endif
3644 let s:netrw_initbookhist= 1
3645 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003648
Bram Moolenaar97d62492012-11-15 21:28:22 +01003649 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3651" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003652" call Dret("s:NetrwBookHistRead")
3653endfun
3654
3655" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003657" Sister function: s:NetrwBookHistRead()
3658" I used to do this via viminfo but that appears to
3659" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003660" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3661" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003662" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003665 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003666" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003667 return
3668 endif
3669
Bram Moolenaar5c736222010-01-06 20:54:52 +01003670 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003671" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003672 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003673
3674 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003676" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003677 if g:netrw_use_noswf
3678 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3679 else
3680 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3681 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003682 setl nocin noai noci magic nospell nohid wig= noaw
3683 setl ma noro write
3684 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003685 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686
Bram Moolenaar85850f32019-07-19 22:05:51 +02003687 " rename enew'd file: .netrwhist -- no attempt to merge
3688 " record dirhistmax and current dirhistcnt
3689 " save history
3690" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003691 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3694 if g:netrw_dirhistmax > 0
3695 let lastline = line("$")
3696 let cnt = g:netrw_dirhistcnt
3697 let first = 1
3698 while ( first || cnt != g:netrw_dirhistcnt )
3699 let lastline= lastline + 1
3700 if exists("g:netrw_dirhist_{cnt}")
3701 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3702" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3703 endif
3704 let first = 0
3705 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3706 if cnt < 0
3707 let cnt= cnt + g:netrw_dirhistmax
3708 endif
3709 endwhile
3710 exe "sil! w! ".savefile
3711" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3712 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003715 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003717" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718 " merge and write .netrwbook
3719 let savefile= s:NetrwHome()."/.netrwbook"
3720
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003721 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003722 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003723 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003724 for bdm in booklist
3725 if index(g:netrw_bookmarklist,bdm) == -1
3726 call add(g:netrw_bookmarklist,bdm)
3727 endif
3728 endfor
3729 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003730 endif
3731
3732 " construct and save .netrwbook
3733 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003734 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003735" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003736 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003737
3738 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003739 let bgone= bufnr("%")
3740 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003741 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742
3743" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003744endfun
3745
3746" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3748" list of the contents of a local or remote directory. It is assumed that the
3749" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3750" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003752fun! s:NetrwBrowse(islocal,dirname)
3753 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003754" 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 +02003755" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3756" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3757" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003758
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003759 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3760 " This is useful when one edits a local file, then :e ., then :Rex
3761 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3762 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003763" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003764 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003766 " s:NetrwBrowse : initialize history {{{3
3767 if !exists("s:netrw_initbookhist")
3768 NetrwKeepj call s:NetrwBookHistRead()
3769 endif
3770
3771 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003772 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003773 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003774" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003775 else
3776 let dirname= a:dirname
3777 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778
Bram Moolenaar85850f32019-07-19 22:05:51 +02003779 " repoint t:netrw_lexbufnr if appropriate
3780 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3781" call Decho("set repointlexbufnr to true!")
3782 let repointlexbufnr= 1
3783 endif
3784
3785 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003786 if exists("s:netrw_skipbrowse")
3787 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003788" 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 +01003789" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003790 return
3791 endif
3792 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003793 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003794" call Dret("s:NetrwBrowse : missing shellescape()")
3795 return
3796 endif
3797 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003798 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003799" call Dret("s:NetrwBrowse : missing fnameescape()")
3800 return
3801 endif
3802
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003803 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003804 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003805
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003806 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003807 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3808 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3809" call Decho("clearing marked files",'~'.expand("<slnum>"))
3810 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003812 endif
3813
3814 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003815 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003816" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3817" 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 +02003818 if s:NetrwLcd(dirname)
3819" call Dret("s:NetrwBrowse : lcd failure")
3820 return
3821 endif
3822 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003823" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824
Bram Moolenaar5c736222010-01-06 20:54:52 +01003825 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003827" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003828 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003829" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003830 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003831 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003833" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834
3835 " remove any filetype indicator from end of dirname, except for the
3836 " "this is a directory" indicator (/).
3837 " There shouldn't be one of those here, anyway.
3838 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003839" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003840 call s:RemotePathAnalysis(dirname)
3841
3842 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3843 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003844 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003845 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003846" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003847 let b:netrw_curdir = dirname
3848 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003849 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003850 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3851 sil call netrw#NetRead(2,url)
3852 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" call Decho("url<".url.">",'~'.expand("<slnum>"))
3854" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3855" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 if s:path =~ '.bz2'
3857 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3858 elseif s:path =~ '.gz'
3859 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3860 elseif s:path =~ '.gz'
3861 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3862 else
3863 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3864 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003865 endif
3866
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003868 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003869 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003872" 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 +00003873
Bram Moolenaar446cb832008-06-24 21:56:24 +00003874" call Dret("s:NetrwBrowse : file<".s:fname.">")
3875 return
3876 endif
3877
Bram Moolenaaradc21822011-04-01 18:03:16 +02003878 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003879 call s:UseBufWinVars()
3880
3881 " set up some variables {{{3
3882 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003883 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003884 let s:last_sort_by = g:netrw_sort_by
3885
3886 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003887 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003888
Bram Moolenaar97d62492012-11-15 21:28:22 +01003889 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003890" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003891 let svpos = winsaveview()
3892" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003894
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003896 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3897 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3898" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3899" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3900 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3901 else
3902" " call Decho("2match none",'~'.expand("<slnum>"))
3903 2match none
3904 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003905 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003906 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003907 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003908" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003909 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003910" 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 +01003911" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912 return
3913 endif
3914
3915 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003916" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003917 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003918 if b:netrw_curdir =~ '[/\\]$'
3919 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3920 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003921 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003922 let b:netrw_curdir= b:netrw_curdir."/"
3923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924 if b:netrw_curdir == ''
3925 if has("amiga")
3926 " On the Amiga, the empty string connotes the current directory
3927 let b:netrw_curdir= getcwd()
3928 else
3929 " under unix, when the root directory is encountered, the result
3930 " from the preceding substitute is an empty string.
3931 let b:netrw_curdir= '/'
3932 endif
3933 endif
3934 if !a:islocal && b:netrw_curdir !~ '/$'
3935 let b:netrw_curdir= b:netrw_curdir.'/'
3936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938
3939 " ------------
3940 " (local only) {{{3
3941 " ------------
3942 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944
3945 " Set up ShellCmdPost handling. Append current buffer to browselist
3946 call s:LocalFastBrowser()
3947
3948 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3949 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003950" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3951" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003952 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003953 if s:NetrwLcd(b:netrw_curdir)
3954" call Dret("s:NetrwBrowse : lcd failure")
3955 return
3956 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003957 endif
3958 endif
3959
3960 " --------------------------------
3961 " remote handling: {{{3
3962 " --------------------------------
3963 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003964" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965
Bram Moolenaar97d62492012-11-15 21:28:22 +01003966 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003967" 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 +02003968 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003969 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3972 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3973 if dirname !~ '/$'
3974 let dirname= dirname.'/'
3975 endif
3976 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003977" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003978 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003979 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003980" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 endif
3982
3983 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3984 if dirname !~ dirpat
3985 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003986 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003987 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003988 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003989" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003990 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" 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 +00003992" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3993 return
3994 endif
3995 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003997 endif " (additional remote handling)
3998
Bram Moolenaar85850f32019-07-19 22:05:51 +02003999 " -------------------------------
4000 " Perform Directory Listing: {{{3
4001 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004002 NetrwKeepj call s:NetrwMaps(a:islocal)
4003 NetrwKeepj call s:NetrwCommands(a:islocal)
4004 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004006 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004007 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004008" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4009
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010 " If there is a rexposn: restore position with rexposn
4011 " Otherwise : set rexposn
4012 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004013" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4014 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4015 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4016 NetrwKeepj exe w:netrw_bannercnt
4017 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018 else
4019 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4020 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004021 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004022 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004024 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004025 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004026
Bram Moolenaar85850f32019-07-19 22:05:51 +02004027 " repoint t:netrw_lexbufnr if appropriate
4028 if exists("repointlexbufnr")
4029 let t:netrw_lexbufnr= bufnr("%")
4030" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4031 endif
4032
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033 " restore position
4034 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004035" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4036 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004037 endif
4038
Bram Moolenaara6878372014-03-22 21:02:50 +01004039 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004040 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4041 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4043" 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 +02004044" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004045 return
4046endfun
4047
4048" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004049" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4050" may not apply correctly; ie. netrw's idea of the current directory may
4051" differ from vim's. This function insures that netrw's idea of the current
4052" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004053" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004055" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4056" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4057" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4058" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4059" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004060
4061 " clean up any leading treedepthstring
4062 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4063 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004064" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004065 else
4066 let fname= a:fname
4067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004068
4069 if g:netrw_keepdir
4070 " vim's idea of the current directory possibly may differ from netrw's
4071 if !exists("b:netrw_curdir")
4072 let b:netrw_curdir= getcwd()
4073 endif
4074
Nir Lichtman1e34b952024-05-08 19:19:34 +02004075 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004076 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004077 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004078 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004080 else
4081 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004082 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004083" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004084 endif
4085
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004086 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004087 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004088 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004089" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004090 else
4091 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004093" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004094 endif
4095 else
4096 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004097 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004098" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4099" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4100" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101 endif
4102
Bram Moolenaar85850f32019-07-19 22:05:51 +02004103" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104 return ret
4105endfun
4106
4107" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004108" s:NetrwFileInfo: supports qf (query for file information) {{{2
4109fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004110" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004111 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004112 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004114 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004116 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 let lsopt= "-lsadh --si"
4118 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004119" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004120 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004121
4122 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004123 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004125
Bram Moolenaara6878372014-03-22 21:02:50 +01004126 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004127 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004129
4130 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004131 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004132" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004133
Bram Moolenaar446cb832008-06-24 21:56:24 +00004134 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004135" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004136 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004138 endif
4139 else
4140 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004141" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4142 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004143 let fname= substitute(a:fname,".$","","")
4144 else
4145 let fname= a:fname
4146 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004147 let t = getftime(s:NetrwFile(fname))
4148 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004149 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 let sz= s:NetrwHumanReadable(sz)
4151 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4153" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 endif
4155 else
4156 echo "sorry, \"qf\" not supported yet for remote files"
4157 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004158 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004159" call Dret("s:NetrwFileInfo")
4160endfun
4161
4162" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004163" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4164fun! s:NetrwFullPath(filename)
4165" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4166 let filename= a:filename
4167 if filename !~ '^/'
4168 let filename= resolve(getcwd().'/'.filename)
4169 endif
4170 if filename != "/" && filename =~ '/$'
4171 let filename= substitute(filename,'/$','','')
4172 endif
4173" " call Dret("s:NetrwFullPath <".filename.">")
4174 return filename
4175endfun
4176
4177" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004178" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004181" 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 +00004182fun! s:NetrwGetBuffer(islocal,dirname)
4183" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004184" 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 +02004185" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4186" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187 let dirname= a:dirname
4188
4189 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004190" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004191 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004192" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004193 let s:netrwbuf= {}
4194 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004195" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4196" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4197
4198 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4199 let bufnum = -1
4200
4201 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4202 if has_key(s:netrwbuf,"NetrwTreeListing")
4203 let bufnum= s:netrwbuf["NetrwTreeListing"]
4204 else
4205 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4206 endif
4207" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4208 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004209 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004210 let bufnum= -1
4211 endif
4212 elseif bufnr("NetrwTreeListing") != -1
4213 let bufnum= bufnr("NetrwTreeListing")
4214" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4215 else
4216" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4217 let bufnum= -1
4218 endif
4219
4220 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004221 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004222" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004223 if !bufexists(bufnum)
4224 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4225 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004226 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004227
Bram Moolenaar446cb832008-06-24 21:56:24 +00004228 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004229" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004230 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004232" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4233
Bram Moolenaar71badf92023-04-22 22:40:14 +01004234 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004235 " IF the buffer already has the desired name
4236 " AND it is empty
4237 let curbuf = bufname("%")
4238 if curbuf == '.'
4239 let curbuf = getcwd()
4240 endif
4241" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004242" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004243" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4244" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4245" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4246" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4247 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004248" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4249 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004250 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004251" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004252 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004253 " 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 +00004254
4255 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004257" 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 +00004258 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004259" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 " name the buffer
4261 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4262 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004263" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004264 let w:netrw_treebufnr = bufnr("%")
4265 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004266 if g:netrw_use_noswf
4267 setl nobl bt=nofile noswf
4268 else
4269 setl nobl bt=nofile
4270 endif
4271 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4272 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4273 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4274 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004275" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004276 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004277 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004278 " enter the new buffer into the s:netrwbuf dictionary
4279 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4280" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4281" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004283" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004284
4285 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004287 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004288 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004289 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004290
4291 if &ft == "netrw"
4292" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4293 exe "sil! NetrwKeepj noswapfile b ".bufnum
4294" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004295 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004296" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4297 call s:NetrwEditBuf(bufnum)
4298" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004299 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004300" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004302 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004304
4305 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004307
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004308 if line("$") <= 1 && getline(1) == ""
4309 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004310 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" 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>"))
4312" 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 +01004313" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4314 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004315
Bram Moolenaar97d62492012-11-15 21:28:22 +01004316 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004317" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004318 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319 sil NetrwKeepj %d _
4320" 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>"))
4321" 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 +01004322" 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 +00004323 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004324
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4327" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004328 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004329 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004330 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331" 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>"))
4332" 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 +01004333" 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 +00004334 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" 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>"))
4338" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4339" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 return 1
4341 endif
4342 endif
4343
4344 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4345 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4346 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4347 " med 1 D H
4348 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349" 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 +00004350 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004352 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353
4354 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4356" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4357 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4360" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4361" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004362 return 0
4363endfun
4364
4365" ---------------------------------------------------------------------
4366" s:NetrwGetcwd: get the current directory. {{{2
4367" Change backslashes to forward slashes, if any.
4368" If doesc is true, escape certain troublesome characters
4369fun! s:NetrwGetcwd(doesc)
4370" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4371 let curdir= substitute(getcwd(),'\\','/','ge')
4372 if curdir !~ '[\/]$'
4373 let curdir= curdir.'/'
4374 endif
4375 if a:doesc
4376 let curdir= fnameescape(curdir)
4377 endif
4378" call Dret("NetrwGetcwd <".curdir.">")
4379 return curdir
4380endfun
4381
4382" ---------------------------------------------------------------------
4383" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4384fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4386" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4387 let keepsol= &l:sol
4388 setl nosol
4389
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 call s:UseBufWinVars()
4391
4392 " insure that w:netrw_liststyle is set up
4393 if !exists("w:netrw_liststyle")
4394 if exists("g:netrw_liststyle")
4395 let w:netrw_liststyle= g:netrw_liststyle
4396 else
4397 let w:netrw_liststyle= s:THINLIST
4398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004399" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400 endif
4401
4402 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4403 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004404" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004405 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406 let dirname= "./"
4407 let curline= getline('.')
4408
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004409 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004410 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004411 let s:netrw_skipbrowse= 1
4412 echo 'Pressing "s" also works'
4413
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004414 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 let s:netrw_skipbrowse= 1
4416 echo 'Press "S" to edit sorting sequence'
4417
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004418 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004419 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004422 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004423 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424 let s:netrw_skipbrowse= 1
4425 echo 'Pressing "a" also works'
4426
4427 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004428 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429 endif
4430
4431 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004432" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004433 NetrwKeepj norm! 0
4434 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435
4436 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004437" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004438 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4440
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004441 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004442" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004443 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004444 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445
4446 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004447" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448 let dirname= getline('.')
4449
4450 if !exists("b:netrw_cpf")
4451 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004452 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 +01004453 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004454" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455 endif
4456
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004457" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004459" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4460" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004461 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004462 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463 else
4464 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004465 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 endif
Enno3146d632024-07-04 19:44:42 +02004467
4468 let dict={}
4469 " save the unnamed register and register 0-9 and a
4470 let dict.a=[getreg('a'), getregtype('a')]
4471 for i in range(0, 9)
4472 let dict[i] = [getreg(i), getregtype(i)]
4473 endfor
4474 let dict.unnamed = [getreg(''), getregtype('')]
4475
Bram Moolenaarc236c162008-07-13 17:41:49 +00004476 let eofname= filestart + b:netrw_cpf + 1
4477 if eofname <= col("$")
4478 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004479 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004480 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004481 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004482 endif
Enno3146d632024-07-04 19:44:42 +02004483
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004485 call s:RestoreRegister(dict)
4486
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 endif
4491
4492 " symlinks are indicated by a trailing "@". Remove it before further processing.
4493 let dirname= substitute(dirname,"@$","","")
4494
4495 " executables are indicated by a trailing "*". Remove it before further processing.
4496 let dirname= substitute(dirname,"\*$","","")
4497
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004498 let &l:sol= keepsol
4499
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500" call Dret("s:NetrwGetWord <".dirname.">")
4501 return dirname
4502endfun
4503
4504" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004505" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4506" g:netrw_bufsettings will be used after the listing is produced.
4507" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508fun! s:NetrwListSettings(islocal)
4509" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" 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 +00004511 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004512" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4513 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4514 setl bt=nofile nobl ma nonu nowrap noro nornu
4515 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004516 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004517 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004519" call Dredir("ls!","s:NetrwListSettings")
4520" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004521 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004522 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004524 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004526 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004528" 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 +00004529" call Dret("s:NetrwListSettings")
4530endfun
4531
4532" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004533" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534" islocal=0: remote browsing
4535" =1: local browsing
4536fun! s:NetrwListStyle(islocal)
4537" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004538
Bram Moolenaar97d62492012-11-15 21:28:22 +01004539 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004540 let fname = s:NetrwGetWord()
4541 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004542 let svpos = winsaveview()
4543" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004545" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4546" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4547" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548
Bram Moolenaar85850f32019-07-19 22:05:51 +02004549 " repoint t:netrw_lexbufnr if appropriate
4550 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4551" call Decho("set repointlexbufnr to true!")
4552 let repointlexbufnr= 1
4553 endif
4554
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555 if w:netrw_liststyle == s:THINLIST
4556 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004557" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004558 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4559
4560 elseif w:netrw_liststyle == s:LONGLIST
4561 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004562" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4564
4565 elseif w:netrw_liststyle == s:WIDELIST
4566 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004567" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4569
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004570 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004571" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4573
4574 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004575 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 let g:netrw_liststyle = s:THINLIST
4577 let w:netrw_liststyle = g:netrw_liststyle
4578 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4579 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004580 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004581" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582
4583 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004584" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4585 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004586 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004588 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004589" 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 +00004590
4591 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004592" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004593 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004594 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004595
Bram Moolenaar85850f32019-07-19 22:05:51 +02004596 " repoint t:netrw_lexbufnr if appropriate
4597 if exists("repointlexbufnr")
4598 let t:netrw_lexbufnr= bufnr("%")
4599" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4600 endif
4601
Bram Moolenaar13600302014-05-22 18:26:40 +02004602 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004605 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004606
4607" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4608endfun
4609
4610" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004611" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4612fun! s:NetrwBannerCtrl(islocal)
4613" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4614
Bram Moolenaar97d62492012-11-15 21:28:22 +01004615 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004616 " toggle the banner (enable/suppress)
4617 let g:netrw_banner= !g:netrw_banner
4618
4619 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004620 let svpos= winsaveview()
4621" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004622 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4623
4624 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004625 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4626 let fname= s:NetrwGetWord()
4627 sil NetrwKeepj $
4628 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4629" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4630 if result <= 0 && exists("w:netrw_bannercnt")
4631 exe "NetrwKeepj ".w:netrw_bannercnt
4632 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004633 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004634 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004635" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4636endfun
4637
4638" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004639" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4640"
4641" No bang: enters files/directories into Netrw's bookmark system
4642" No argument and in netrw buffer:
4643" if there are marked files: bookmark marked files
4644" otherwise : bookmark file/directory under cursor
4645" No argument and not in netrw buffer: bookmarks current open file
4646" Has arguments: globs them individually and bookmarks them
4647"
4648" With bang: deletes files/directories from Netrw's bookmark system
4649fun! s:NetrwBookmark(del,...)
4650" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4651 if a:0 == 0
4652 if &ft == "netrw"
4653 let curbufnr = bufnr("%")
4654
4655 if exists("s:netrwmarkfilelist_{curbufnr}")
4656 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004657" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004658 let svpos = winsaveview()
4659" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004660 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004661 for fname in s:netrwmarkfilelist_{curbufnr}
4662 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4663 endfor
4664 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4665 call s:NetrwUnmarkList(curbufnr,curdir)
4666 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004667" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4668 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004669 else
4670 let fname= s:NetrwGetWord()
4671 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4672 endif
4673
4674 else
4675 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004676" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004677 let fname= expand("%")
4678 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4679 endif
4680
4681 else
4682 " bookmark specified files
4683 " attempts to infer if working remote or local
4684 " by deciding if the current file begins with an url
4685 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004686 let islocal= expand("%") !~ '^\a\{3,}://'
4687" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004688 let i = 1
4689 while i <= a:0
4690 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004691 if v:version > 704 || (v:version == 704 && has("patch656"))
4692 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004693 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004694 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004695 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004696 else
4697 let mbfiles= [a:{i}]
4698 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004699" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004700 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004701" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4703 endfor
4704 let i= i + 1
4705 endwhile
4706 endif
4707
4708 " update the menu
4709 call s:NetrwBookmarkMenu()
4710
4711" call Dret("s:NetrwBookmark")
4712endfun
4713
4714" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004715" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4716" .2.[cnt] for bookmarks, and
4717" .3.[cnt] for history
4718" (see s:NetrwMenu())
4719fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004720 if !exists("s:netrw_menucnt")
4721 return
4722 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004723" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004724
4725 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004726 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004727 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004728" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004729 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4730 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004731 endif
4732 if !exists("s:netrw_initbookhist")
4733 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004734 endif
4735
4736 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004737 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004738 let cnt= 1
4739 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004740" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004741 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004742
4743 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004744 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004745
4746 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004747 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 +01004748 let cnt= cnt + 1
4749 endfor
4750
4751 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752
4753 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004754 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004755 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004756 let first = 1
4757 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004758 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004759 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004760 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004761 if exists("g:netrw_dirhist_{cnt}")
4762 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004764 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4765 endif
4766 let first = 0
4767 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4768 if cnt < 0
4769 let cnt= cnt + g:netrw_dirhistmax
4770 endif
4771 endwhile
4772 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004773
Bram Moolenaar9964e462007-05-05 17:54:07 +00004774 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004775" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776endfun
4777
4778" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004779" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4780" directory and a new directory name. Also, if the
4781" "new directory name" is actually a file,
4782" NetrwBrowseChgDir() edits the file.
4783fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004784" 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 +01004785" 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 +00004786
Bram Moolenaar97d62492012-11-15 21:28:22 +01004787 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004788 if !exists("b:netrw_curdir")
4789 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4790 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004791 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004792" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4793" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004794" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004797 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004798" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004799
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004800 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004801" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004802 call s:SavePosn(s:netrw_posn)
4803 NetrwKeepj call s:NetrwOptionsSave("s:")
4804 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004805 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004806 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004807 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004808 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004809 endif
4810 let newdir = a:newdir
4811 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004812 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004813" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004814" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004815" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004816
4817 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004818" 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 +01004819 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004820" 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 +01004821 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004822 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004823" 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 +01004824 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004825" 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 +02004826 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004827 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004828 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004829 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004830" 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 +01004831 endif
4832 endif
4833" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004834" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004835 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004836
Bram Moolenaar446cb832008-06-24 21:56:24 +00004837 " set up o/s-dependent directory recognition pattern
4838 if has("amiga")
4839 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004840 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004841 let dirpat= '[\/]$'
4842 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004844
4845 if dirname !~ dirpat
4846 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004847 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004849" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004850 endif
4851
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004852" 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 +01004853 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004854 " ------------------------------
4855 " NetrwBrowseChgDir: edit a file {{{3
4856 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004857" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004858
Bram Moolenaar97d62492012-11-15 21:28:22 +01004859 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004860 let s:rexposn_{bufnr("%")}= winsaveview()
4861" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004862" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4863" 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 +01004864
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4867" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004868" let newdir = s:NetrwTreePath(s:netrw_treetop)
4869" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004870 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004871 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4872" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4873 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 if dirname =~ '/$'
4875 let dirname= dirname.newdir
4876 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004877 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4880" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004882" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004884 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004888 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004889 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004890" 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 +02004891 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004892 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004893 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004894" " 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 +01004895 if type(g:netrw_browse_split) == 3
4896 " open file in server
4897 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004898" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004899 call s:NetrwServerEdit(a:islocal,dirname)
4900" call Dret("s:NetrwBrowseChgDir")
4901 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004902
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004903 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004904 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004905" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004906 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4907 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004908 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004909 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004910 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004911 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004912
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004914 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004915" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004916 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4917 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004918 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004919 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004920 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004921 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004922
Bram Moolenaar446cb832008-06-24 21:56:24 +00004923 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004924 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004926 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004927 if !exists("b:netrw_curdir")
4928 let b:netrw_curdir= getcwd()
4929 endif
4930 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004931
Bram Moolenaar446cb832008-06-24 21:56:24 +00004932 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004933 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004934" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004935 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004936 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004937" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004938 return
4939 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004940 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004941
Bram Moolenaar9964e462007-05-05 17:54:07 +00004942 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004944" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004945 call s:NetrwMenu(0)
4946 " optional change to window
4947 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004948" 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 +02004949 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004950 " if g:netrw_chgwin is set to one more than the last window, then
4951 " vertically split the last window to make that window available.
4952 let curwin= winnr()
4953 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4954 vs
4955 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004956 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004957 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004958 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004959 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004960 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004961
Bram Moolenaar9964e462007-05-05 17:54:07 +00004962 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004963
Bram Moolenaar446cb832008-06-24 21:56:24 +00004964 " the point where netrw actually edits the (local) file
4965 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004966 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004967 if !&mod
4968 " if e the new file would fail due to &mod, then don't change any of the flags
4969 let dolockout= 1
4970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004972" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004973 " some like c-^ to return to the last edited file
4974 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004975 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4976 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004977 call s:NetrwEditFile("e","",dirname)
4978" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004979 " COMBAK -- cuc cul related
4980 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004981 if &hidden || &bufhidden == "hide"
4982 " file came from vim's hidden storage. Don't "restore" options with it.
4983 let dorestore= 0
4984 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004985 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004986" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004987 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004988
4989 " handle g:Netrw_funcref -- call external-to-netrw functions
4990 " This code will handle g:Netrw_funcref as an individual function reference
4991 " or as a list of function references. It will ignore anything that's not
4992 " a function reference. See :help Funcref for information about function references.
4993 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004994" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004995 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004996" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004997 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004998 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004999" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005000 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005001 if type(Fncref) == 2
5002 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005003 endif
5004 endfor
5005 endif
5006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005007 endif
5008
5009 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005010 " ----------------------------------------------------
5011 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5012 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005013" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005014 let dirname = newdir
5015 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005016 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005018
5019 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005020 " ---------------------------------------------
5021 " NetrwBrowseChgDir: refresh the directory list {{{3
5022 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005023" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005024 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005026
5027 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005028 " --------------------------------------
5029 " NetrwBrowseChgDir: go up one directory {{{3
5030 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005031" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005032
5033 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5034 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005035" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5036" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005037 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005039 endif
5040
5041 if has("amiga")
5042 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005043" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005044 if a:islocal
5045 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5046 let dirname= substitute(dirname,'/$','','')
5047 else
5048 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5049 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005050" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005051
Nir Lichtman1e34b952024-05-08 19:19:34 +02005052 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005053 " windows
5054 if a:islocal
5055 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5056 if dirname == ""
5057 let dirname= '/'
5058 endif
5059 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005060 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005061 endif
5062 if dirname =~ '^\a:$'
5063 let dirname= dirname.'/'
5064 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005065" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005066
Bram Moolenaar446cb832008-06-24 21:56:24 +00005067 else
5068 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005069" 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 +00005070 if a:islocal
5071 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5072 if dirname == ""
5073 let dirname= '/'
5074 endif
5075 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005078" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005080 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005081 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005082
5083 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005084 " --------------------------------------
5085 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5086 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005087" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005088 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5089" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005090 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005091 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005092" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5093 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005094 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005095 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005097 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005098 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100
5101 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005102" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005104" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105 let haskey= 1
5106 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005107" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108 endif
5109
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005111" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113 if has_key(w:netrw_treedict,treedir."/")
5114 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005115" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116 let haskey = 1
5117 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005118" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005119 endif
5120 endif
5121
5122 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005123" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124 if !haskey && treedir =~ '/$'
5125 let treedir= substitute(treedir,'/$','','')
5126 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005127" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 let haskey = 1
5129 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005130" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 endif
5132 endif
5133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 if haskey
5136 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005137" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005139" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5140" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005141 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 else
5143 " go down one directory
5144 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005145" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5146" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005148 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005149" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005150 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151
5152 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005153 " ----------------------------------------
5154 " NetrwBrowseChgDir: Go down one directory {{{3
5155 " ----------------------------------------
5156 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005158 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005160 endif
5161
Bram Moolenaar97d62492012-11-15 21:28:22 +01005162 " --------------------------------------
5163 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5164 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005165 if dorestore
5166 " dorestore is zero'd when a local file was hidden or bufhidden;
5167 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005169 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005170" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005171" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005172 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005173 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005175 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005176" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5177" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005178 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005179" 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 +02005180 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005181" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5182" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005183 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005184" 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 +02005185 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005186 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005187 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005188 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005189
Bram Moolenaar446cb832008-06-24 21:56:24 +00005190" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5191 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005192endfun
5193
5194" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005195" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5196" for thin, long, and wide: cursor placed just after banner
5197" for tree, keeps cursor on current filename
5198fun! s:NetrwBrowseUpDir(islocal)
5199" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005200 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5201 " this test needed because occasionally this function seems to be incorrectly called
5202 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005204 " directories.
5205" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5206 return
5207 endif
5208
Bram Moolenaara6878372014-03-22 21:02:50 +01005209 norm! 0
5210 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005211" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005212 let curline= getline(".")
5213 let swwline= winline() - 1
5214 if exists("w:netrw_treetop")
5215 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005216 elseif exists("b:netrw_curdir")
5217 let w:netrw_treetop= b:netrw_curdir
5218 else
5219 let w:netrw_treetop= getcwd()
5220 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005221 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005222 let curfile = getline(".")
5223 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005224 if a:islocal
5225 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5226 else
5227 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5228 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005229" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5230" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5231 if w:netrw_treetop == '/'
5232 keepj call search('^\M'.curfile,"w")
5233 elseif curfile == '../'
5234 keepj call search('^\M'.curfile,"wb")
5235 else
5236" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5237 while 1
5238 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5239 let treepath= s:NetrwTreePath(w:netrw_treetop)
5240" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5241 if treepath == curpath
5242 break
5243 endif
5244 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005246
Bram Moolenaara6878372014-03-22 21:02:50 +01005247 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005248" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005249 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005250 if exists("b:netrw_curdir")
5251 let curdir= b:netrw_curdir
5252 else
5253 let curdir= expand(getcwd())
5254 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005255 if a:islocal
5256 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5257 else
5258 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005260 call s:RestorePosn(s:netrw_posn)
5261 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005262 let curdir= '\<'. escape(curdir, '~'). '/'
5263 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005264 endif
5265" call Dret("s:NetrwBrowseUpDir")
5266endfun
5267
5268" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005269" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005270" given filename; typically this means given their extension.
5271" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005272fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005273 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005274" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005275
Bram Moolenaar91359012019-11-30 17:57:03 +01005276 if a:remote == 0 && isdirectory(a:fname)
5277 " if its really just a local directory, then do a "gf" instead
5278" 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 +01005279" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5280 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005281" call Dret("netrw#BrowseX")
5282 return
5283 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5284 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5285" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5286" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5287" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5288" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5289 norm! gf
5290" call Dret("netrw#BrowseX")
5291 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005292 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005293" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005294
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005295 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5296 let remote = a:remote
5297 else
5298 let remote = 0
5299 endif
5300
Bram Moolenaar97d62492012-11-15 21:28:22 +01005301 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005302 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005303" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005304
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005305 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5306 let awkeep = &aw
5307 set noaw
5308
Bram Moolenaar5c736222010-01-06 20:54:52 +01005309 " special core dump handler
5310 if a:fname =~ '/core\(\.\d\+\)\=$'
5311 if exists("g:Netrw_corehandler")
5312 if type(g:Netrw_corehandler) == 2
5313 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005314" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005315 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005316 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005317 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005318" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005319 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005320 if type(Fncref) == 2
5321 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005322 endif
5323 endfor
5324 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005325" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005326 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005327 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328 let &aw= awkeep
5329" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005330 return
5331 endif
5332 endif
5333
Bram Moolenaar446cb832008-06-24 21:56:24 +00005334 " set up the filename
5335 " (lower case the extension, make a local copy of a remote file)
5336 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005337 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005338 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005339 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005340 if exten =~ "[\\/]"
5341 let exten= ""
5342 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005343" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005344
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005345 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005346 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005347" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005348 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005349 call netrw#NetRead(3,a:fname)
5350 " attempt to rename tempfile
5351 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005352 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005353" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5354" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005355 if s:netrw_tmpfile != newname && newname != ""
5356 if rename(s:netrw_tmpfile,newname) == 0
5357 " renaming succeeded
5358" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5359 let fname= newname
5360 else
5361 " renaming failed
5362" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5363 let fname= s:netrw_tmpfile
5364 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005365 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005366 let fname= s:netrw_tmpfile
5367 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005368 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005369" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005370 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005371 " special ~ handler for local
5372 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005373" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5374 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005376 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005377" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5378" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005379
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005380 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005381 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005382" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005383 if g:netrw_browsex_viewer =~ '\s'
5384 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5385 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5386 let oviewer = ''
5387 let cnt = 1
5388 while !executable(viewer) && viewer != oviewer
5389 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5390 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5391 let cnt = cnt + 1
5392 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005393" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005394 endwhile
5395 else
5396 let viewer = g:netrw_browsex_viewer
5397 let viewopt = ""
5398 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005399" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005400 endif
5401
Luca Saccarolaa7d45612024-10-21 21:27:03 +02005402 if exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005403" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Konfekt3d7e5672024-10-27 22:16:49 +01005404 exe 'Launch' viewer viewopt shellescape(fname, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405 else
Konfekt3d7e5672024-10-27 22:16:49 +01005406 " though shellescape(..., 1) is used in Open, it's insufficient
5407 exe 'Open' escape(fname, '#%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005408 endif
5409
Bram Moolenaar446cb832008-06-24 21:56:24 +00005410 " cleanup: remove temporary file,
5411 " delete current buffer if success with handler,
5412 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005413 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005414 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005415" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005416"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005417" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418" endif
5419
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005420 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005421 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005423 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005425 if use_ctrlo
5426 exe "sil! NetrwKeepj norm! \<c-o>"
5427 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005429" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005430 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005431 let @@ = ykeep
5432 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005433
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005434" call Dret("netrw#BrowseX")
5435endfun
5436
5437" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005438" netrw#GX: gets word under cursor for gx support {{{2
5439" See also: netrw#BrowseXVis
5440" netrw#BrowseX
5441fun! netrw#GX()
5442" call Dfunc("netrw#GX()")
5443 if &ft == "netrw"
5444 let fname= s:NetrwGetWord()
5445 else
Konfekt3d7e5672024-10-27 22:16:49 +01005446 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005447 endif
5448" call Dret("netrw#GX <".fname.">")
5449 return fname
5450endfun
5451
Konfekt3d7e5672024-10-27 22:16:49 +01005452fun! s:GetURL() abort
5453 let URL = ''
5454 if exists('*Netrw_get_URL_' .. &filetype)
5455 let URL = call('Netrw_get_URL_' .. &filetype, [])
5456 endif
5457 if !empty(URL) | return URL | endif
5458 " URLs end in letter, digit or forward slash
5459 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5460 if !empty(URL) | return URL | endif
5461
5462 " Is it a file in the current work dir ...
5463 let file = expand("<cfile>")
5464 if filereadable(file) | return file | endif
5465 " ... or in that of the current buffer?
5466 let path = fnamemodify(expand('%'), ':p')
5467 if isdirectory(path)
5468 let dir = path
5469 elseif filereadable(path)
5470 let dir = fnamemodify(path, ':h')
5471 endif
5472 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5473
5474 return ''
5475endf
5476
Bram Moolenaar85850f32019-07-19 22:05:51 +02005477" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005478" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5479fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005480 let dict={}
5481 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005482 norm! gv"ay
5483 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005484 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005485 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005486endfun
5487
5488" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005489" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5490" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5491" to become an unlisted buffer, so in that case don't bwipe it.
5492fun! s:NetrwBufRename(newname)
5493" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5494" call Dredir("ls!","s:NetrwBufRename (before rename)")
5495 let oldbufname= bufname(bufnr("%"))
5496" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5497
5498 if oldbufname != a:newname
5499" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5500 let b:junk= 1
5501" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5502 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005503" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005504 let oldbufnr= bufnr(oldbufname)
5505" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5506" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5507 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5508" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5509 exe "bwipe! ".oldbufnr
5510" else " Decho
5511" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005512" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5513" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5514" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005515 endif
5516" call Dredir("ls!","s:NetrwBufRename (after rename)")
5517" else " Decho
5518" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5519 endif
5520
5521" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5522endfun
5523
5524" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005525" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005526fun! netrw#CheckIfRemote(...)
5527" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5528 if a:0 > 0
5529 let curfile= a:1
5530 else
5531 let curfile= expand("%")
5532 endif
5533" call Decho("curfile<".curfile.">")
5534 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005535" call Dret("netrw#CheckIfRemote 1")
5536 return 1
5537 else
5538" call Dret("netrw#CheckIfRemote 0")
5539 return 0
5540 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005541endfun
5542
5543" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005544" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5545fun! s:NetrwChgPerm(islocal,curdir)
5546" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005547 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005548 call inputsave()
5549 let newperm= input("Enter new permission: ")
5550 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005551 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5552 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5553" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005554 call system(chgperm)
5555 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005557 endif
5558 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005559 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005560 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005561 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005562" call Dret("s:NetrwChgPerm")
5563endfun
5564
5565" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005566" s:CheckIfKde: checks if kdeinit is running {{{2
5567" Returns 0: kdeinit not running
5568" 1: kdeinit is running
5569fun! s:CheckIfKde()
5570" call Dfunc("s:CheckIfKde()")
5571 " seems kde systems often have gnome-open due to dependencies, even though
5572 " gnome-open's subsidiary display tools are largely absent. Kde systems
5573 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5574 if !exists("s:haskdeinit")
5575 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005576 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005577 if v:shell_error
5578 let s:haskdeinit = 0
5579 endif
5580 else
5581 let s:haskdeinit= 0
5582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005583" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005584 endif
5585
5586" call Dret("s:CheckIfKde ".s:haskdeinit)
5587 return s:haskdeinit
5588endfun
5589
5590" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005591" s:NetrwClearExplore: clear explore variables (if any) {{{2
5592fun! s:NetrwClearExplore()
5593" call Dfunc("s:NetrwClearExplore()")
5594 2match none
5595 if exists("s:explore_match") |unlet s:explore_match |endif
5596 if exists("s:explore_indx") |unlet s:explore_indx |endif
5597 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5598 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5599 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5600 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5601 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5602 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5603 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5604" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005605" call Dret("s:NetrwClearExplore")
5606endfun
5607
5608" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005609" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5610fun! s:NetrwEditBuf(bufnum)
5611" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5612 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5613" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5614 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5615 else
5616" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005617 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005618 endif
5619" call Dret("s:NetrwEditBuf")
5620endfun
5621
5622" ---------------------------------------------------------------------
5623" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5624" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5625fun! s:NetrwEditFile(cmd,opt,fname)
5626" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5627 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5628" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5629 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5630 else
5631" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005632 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5633 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5634 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005635 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5636 endif
5637" call Dret("s:NetrwEditFile")
5638endfun
5639
5640" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641" s:NetrwExploreListUniq: {{{2
5642fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005643" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005644
5645 " this assumes that the list is already sorted
5646 let newexplist= []
5647 for member in a:explist
5648 if !exists("uniqmember") || member != uniqmember
5649 let uniqmember = member
5650 let newexplist = newexplist + [ member ]
5651 endif
5652 endfor
5653
Bram Moolenaar15146672011-10-20 22:22:38 +02005654" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 return newexplist
5656endfun
5657
5658" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005659" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5660fun! s:NetrwForceChgDir(islocal,newdir)
5661" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005662 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005663 if a:newdir !~ '/$'
5664 " ok, looks like force is needed to get directory-style treatment
5665 if a:newdir =~ '@$'
5666 let newdir= substitute(a:newdir,'@$','/','')
5667 elseif a:newdir =~ '[*=|\\]$'
5668 let newdir= substitute(a:newdir,'.$','/','')
5669 else
5670 let newdir= a:newdir.'/'
5671 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005672" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005673 else
5674 " should already be getting treatment as a directory
5675 let newdir= a:newdir
5676 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005677 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005678 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005679 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005680" call Dret("s:NetrwForceChgDir")
5681endfun
5682
5683" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005684" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005685" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5686" expr : this is the expression to follow the directory. Will use s:ComposePath()
5687" pare =1: remove the current directory from the resulting glob() filelist
5688" =0: leave the current directory in the resulting glob() filelist
5689fun! s:NetrwGlob(direntry,expr,pare)
5690" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005691 if netrw#CheckIfRemote()
5692 keepalt 1sp
5693 keepalt enew
5694 let keep_liststyle = w:netrw_liststyle
5695 let w:netrw_liststyle = s:THINLIST
5696 if s:NetrwRemoteListing() == 0
5697 keepj keepalt %s@/@@
5698 let filelist= getline(1,$)
5699 q!
5700 else
5701 " remote listing error -- leave treedict unchanged
5702 let filelist= w:netrw_treedict[a:direntry]
5703 endif
5704 let w:netrw_liststyle= keep_liststyle
5705 else
Christian Brabandt14879472024-06-13 21:25:35 +02005706 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005707 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005708 " escape [ so it is not detected as wildcard character, see :h wildcard
5709 let path= substitute(path, '[', '[[]', 'g')
5710 endif
5711 if v:version > 704 || (v:version == 704 && has("patch656"))
5712 let filelist= glob(path,0,1,1)
5713 else
5714 let filelist= glob(path,0,1)
5715 endif
5716 if a:pare
5717 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5718 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005719 endif
5720" call Dret("s:NetrwGlob ".string(filelist))
5721 return filelist
5722endfun
5723
5724" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005725" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5726fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005727" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005728 if a:newfile =~ '[/@*=|\\]$'
5729 let newfile= substitute(a:newfile,'.$','','')
5730 else
5731 let newfile= a:newfile
5732 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005733 if a:islocal
5734 call s:NetrwBrowseChgDir(a:islocal,newfile)
5735 else
5736 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5737 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005738" call Dret("s:NetrwForceFile")
5739endfun
5740
5741" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005742" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5743" and switches the hiding mode. The actual hiding is done by
5744" s:NetrwListHide().
5745" g:netrw_hide= 0: show all
5746" 1: show not-hidden files
5747" 2: show hidden files only
5748fun! s:NetrwHide(islocal)
5749" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005750 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005751 let svpos= winsaveview()
5752" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005753
5754 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005755" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5756" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005757
5758 " hide the files in the markfile list
5759 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005760" 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 +00005761 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5762 " remove fname from hiding list
5763 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5764 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5765 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005766" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005767 else
5768 " append fname to hiding list
5769 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5770 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5771 else
5772 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5773 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005774" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005775 endif
5776 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005777 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005778 let g:netrw_hide= 1
5779
5780 else
5781
5782 " switch between show-all/show-not-hidden/show-hidden
5783 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005784 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005785 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005786 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005787 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005788" call Dret("NetrwHide")
5789 return
5790 endif
5791 endif
5792
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005793 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005794" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5795 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005796 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005797" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005798endfun
5799
5800" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005801" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5802fun! s:NetrwHideEdit(islocal)
5803" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5804
5805 let ykeep= @@
5806 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005807 let svpos= winsaveview()
5808" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005809
5810 " get new hiding list from user
5811 call inputsave()
5812 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5813 call inputrestore()
5814 let g:netrw_list_hide= newhide
5815" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5816
5817 " refresh the listing
5818 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5819
5820 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005821" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5822 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005823 let @@= ykeep
5824
5825" call Dret("NetrwHideEdit")
5826endfun
5827
5828" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005829" s:NetrwHidden: invoked by "gh" {{{2
5830fun! s:NetrwHidden(islocal)
5831" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005832 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005833 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005834 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005835" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005836
5837 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005838 " remove .file pattern from hiding list
5839" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005840 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005841 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005842" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005843 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5844 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005845" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005846 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5847 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005848 if g:netrw_list_hide =~ '^,'
5849 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5850 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005851
5852 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005853 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005854" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5855 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005856 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005857" call Dret("s:NetrwHidden")
5858endfun
5859
5860" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005861" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5862fun! s:NetrwHome()
5863 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005864 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005865 else
5866 " go to vim plugin home
5867 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005869 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005870 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005871 let home= basehome."/.vim"
5872 break
5873 endif
5874 endfor
5875 if home == ""
5876 " just pick the first directory
5877 let home= substitute(&rtp,',.*$','','')
5878 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005879 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005880 let home= substitute(home,'/','\\','g')
5881 endif
5882 endif
5883 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005884 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005885" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005886 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005887" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005888 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005889 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005890" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005891 call mkdir(home)
5892 endif
5893 endif
5894 let g:netrw_home= home
5895 return home
5896endfun
5897
5898" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005899" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5900fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005901 if exists("s:netrwdrag")
5902 return
5903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005904 if &ft != "netrw"
5905 return
5906 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005908
Bram Moolenaar97d62492012-11-15 21:28:22 +01005909 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005910 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005911 while getchar(0) != 0
5912 "clear the input stream
5913 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005914 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005915 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005916 let mouse_lnum = v:mouse_lnum
5917 let wlastline = line('w$')
5918 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005919" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5920" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005921 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5922 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005923 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005924" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5925 return
5926 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005927 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005928 " 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 +01005929 " without this test when its disabled.
5930 " 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 +01005931" 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 +01005932 if v:mouse_col > virtcol('.')
5933 let @@= ykeep
5934" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5935 return
5936 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005937
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938 if a:islocal
5939 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005940 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005941 endif
5942 else
5943 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005944 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945 endif
5946 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005947 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948" call Dret("s:NetrwLeftmouse")
5949endfun
5950
5951" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005952" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5953fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005954 if &ft != "netrw"
5955 return
5956 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005957" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5958 call s:NetrwMarkFileTgt(a:islocal)
5959" call Dret("s:NetrwCLeftmouse")
5960endfun
5961
5962" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005963" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5964" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005965" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005966" a:islocal=2 : <c-r> used, remote
5967" a:islocal=3 : <c-r> used, local
5968fun! s:NetrwServerEdit(islocal,fname)
5969" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5970 let islocal = a:islocal%2 " =0: remote =1: local
5971 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005972" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005973
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005974 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005975 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005976 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005977" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005978 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005979 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005980 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5981 unlet s:netrw_browse_split_{winnr()}
5982 endif
5983 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5984" call Dret("s:NetrwServerEdit")
5985 return
5986 endif
5987
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005988" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005989 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005990" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005991
5992 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005993" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005994 let srvrname = g:netrw_browse_split[0]
5995 let tabnum = g:netrw_browse_split[1]
5996 let winnum = g:netrw_browse_split[2]
5997
5998 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005999" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006000
6001 if !ctrlr
6002 " user must have closed the server window and the user did not use <c-r>, but
6003 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006004" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006005 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006006 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006007 endif
6008 let g:netrw_browse_split= 0
6009 if exists("s:netrw_browse_split_".winnr())
6010 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6011 endif
6012 call s:NetrwBrowseChgDir(islocal,a:fname)
6013" call Dret("s:NetrwServerEdit")
6014 return
6015
6016 elseif has("win32") && executable("start")
6017 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006018" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006019 call system("start gvim --servername ".srvrname)
6020
6021 else
6022 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006023" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006024 call system("gvim --servername ".srvrname)
6025 endif
6026 endif
6027
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006028" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006029 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6030 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006031 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006032
6033 else
6034
6035 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6036
6037 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006038" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006039 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006040 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006041 endif
6042 let g:netrw_browse_split= 0
6043 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6044" call Dret("s:NetrwServerEdit")
6045 return
6046
6047 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006048" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006049 if has("win32") && executable("start")
6050 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006052 call system("start gvim --servername ".g:netrw_servername)
6053 else
6054 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006055" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006056 call system("gvim --servername ".g:netrw_servername)
6057 endif
6058 endif
6059 endif
6060
6061 while 1
6062 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006063" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6064 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006065 break
6066 catch /^Vim\%((\a\+)\)\=:E241/
6067 sleep 200m
6068 endtry
6069 endwhile
6070
6071 if exists("g:netrw_browse_split")
6072 if type(g:netrw_browse_split) != 3
6073 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6074 endif
6075 unlet g:netrw_browse_split
6076 endif
6077 let g:netrw_browse_split= [g:netrw_servername,1,1]
6078 endif
6079
6080 else
6081 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6082 endif
6083
6084" call Dret("s:NetrwServerEdit")
6085endfun
6086
6087" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006088" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6089fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006090 if &ft != "netrw"
6091 return
6092 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006093" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006094
Bram Moolenaar8d043172014-01-23 14:24:41 +01006095 let s:ngw= s:NetrwGetWord()
6096 call s:NetrwMarkFile(a:islocal,s:ngw)
6097
6098" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006099endfun
6100
6101" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006102" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6103" Used to mark multiple files.
6104fun! s:NetrwSLeftdrag(islocal)
6105" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6106 if !exists("s:netrwdrag")
6107 let s:netrwdrag = winnr()
6108 if a:islocal
6109 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006110 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006111 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006112 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006113 endif
6114 let ngw = s:NetrwGetWord()
6115 if !exists("s:ngw") || s:ngw != ngw
6116 call s:NetrwMarkFile(a:islocal,ngw)
6117 endif
6118 let s:ngw= ngw
6119" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6120endfun
6121
6122" ---------------------------------------------------------------------
6123" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6124fun! s:NetrwSLeftrelease(islocal)
6125" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6126 if exists("s:netrwdrag")
6127 nunmap <s-leftrelease>
6128 let ngw = s:NetrwGetWord()
6129 if !exists("s:ngw") || s:ngw != ngw
6130 call s:NetrwMarkFile(a:islocal,ngw)
6131 endif
6132 if exists("s:ngw")
6133 unlet s:ngw
6134 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006135 unlet s:netrwdrag
6136 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006137" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006138endfun
6139
6140" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006141" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6142" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006143fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006144" 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 +02006145" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006146 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006147
6148 " 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 +02006149 " How-it-works: take the hiding command, convert it into a range.
6150 " Duplicate characters don't matter.
6151 " Remove all such characters from the '/~@#...890' string.
6152 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006153" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006154 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006155 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006156" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006157
6158 while listhide != ""
6159 if listhide =~ ','
6160 let hide = substitute(listhide,',.*$','','e')
6161 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6162 else
6163 let hide = listhide
6164 let listhide = ""
6165 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006166" 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 +01006167 if g:netrw_sort_by =~ '^[ts]'
6168 if hide =~ '^\^'
6169" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6170 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6171 elseif hide =~ '^\\(\^'
6172 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6173 endif
6174" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6175 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006176
6177 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006178" 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 +00006179 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006180" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006181 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006182 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006183" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006184 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006185 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006186" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006187 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006188
Bram Moolenaar446cb832008-06-24 21:56:24 +00006189 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006190 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006191" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006192 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006193" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006194 endif
6195
Bram Moolenaaradc21822011-04-01 18:03:16 +02006196 " remove any blank lines that have somehow remained.
6197 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006198 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006199
Bram Moolenaar97d62492012-11-15 21:28:22 +01006200 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006201" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006202endfun
6203
6204" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006205" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006206" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006207fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006208" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006209
Bram Moolenaar97d62492012-11-15 21:28:22 +01006210 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006211 " get name of new directory from user. A bare <CR> will skip.
6212 " if its currently a directory, also request will be skipped, but with
6213 " a message.
6214 call inputsave()
6215 let newdirname= input("Please give directory name: ")
6216 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006217" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006218
6219 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006220 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006221" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006222 return
6223 endif
6224
6225 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006226" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006227
6228 " Local mkdir:
6229 " sanity checks
6230 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006231" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6232 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006233 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006234 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006236 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006237" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006238 return
6239 endif
6240 if s:FileReadable(fullnewdir)
6241 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006242 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006243 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006244 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006245" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006246 return
6247 endif
6248
6249 " requested new local directory is neither a pre-existing file or
6250 " directory, so make it!
6251 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006252 if has("unix")
6253 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6254 else
6255 call mkdir(fullnewdir,"p")
6256 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006257 else
6258 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006259 if s:NetrwLcd(b:netrw_curdir)
6260" call Dret("s:NetrwMakeDir : lcd failure")
6261 return
6262 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006263" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006264 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006265 if v:shell_error != 0
6266 let @@= ykeep
6267 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 +01006268" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006269 return
6270 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006272" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006273 if s:NetrwLcd(netrw_origdir)
6274" call Dret("s:NetrwBrowse : lcd failure")
6275 return
6276 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277 endif
6278 endif
6279
6280 if v:shell_error == 0
6281 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006282" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006283 let svpos= winsaveview()
6284" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006286" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6287 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006288 elseif !exists("g:netrw_quiet")
6289 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6290 endif
6291" redraw!
6292
6293 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006294 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006295" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6297 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006298 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299 if v:shell_error == 0
6300 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006301 let svpos= winsaveview()
6302" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006304" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6305 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006307 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 endif
6309" redraw!
6310
6311 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006312 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006313 let svpos= winsaveview()
6314" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006315" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006316 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006317" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006318 let remotepath= b:netrw_fname
6319 else
6320 let remotepath= ""
6321 endif
6322 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006323 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006324" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6325 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006326
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006328 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006329 let svpos= winsaveview()
6330" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006331" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006332 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006333" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006334 let remotepath= b:netrw_fname
6335 else
6336 let remotepath= ""
6337 endif
6338 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006339 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006340" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6341 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342 endif
6343
Bram Moolenaar97d62492012-11-15 21:28:22 +01006344 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006345" call Dret("s:NetrwMakeDir")
6346endfun
6347
6348" ---------------------------------------------------------------------
6349" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6350fun! s:TreeSqueezeDir(islocal)
6351" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6352 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6353 " its a tree-listing style
6354 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006355 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006356 let depth = strchars(substitute(curdepth,' ','','g'))
6357 let srch = -1
6358" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6359" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006361" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6362 if depth >= 2
6363 NetrwKeepj norm! 0
6364 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6365 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6366" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6367" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6368 elseif depth == 1
6369 NetrwKeepj norm! 0
6370 let treedepthchr= substitute(s:treedepthstring,' ','','')
6371 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6372" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6373 endif
6374 if srch > 0
6375" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6376 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6377 exe srch
6378 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006379 endif
6380" call Dret("s:TreeSqueezeDir")
6381endfun
6382
6383" ---------------------------------------------------------------------
6384" s:NetrwMaps: {{{2
6385fun! s:NetrwMaps(islocal)
6386" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6387
Bram Moolenaar85850f32019-07-19 22:05:51 +02006388 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006389 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006390" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006391 if !hasmapto("<Plug>NetrwReturn")
6392 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006393" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006394 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6395 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006396" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006397 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6398 endif
6399 endif
6400 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006401" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006402 endif
6403
Bram Moolenaar85850f32019-07-19 22:05:51 +02006404 " generate default <Plug> maps {{{3
6405 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006406 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006407 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6408 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6409 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6410 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6411 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6412 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6413 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6414 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6415 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6416 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6417" ---------------------------------------------------------------------
6418" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6419" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6420" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6421" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6422" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6423" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6424" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6425" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6426" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6427" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6428" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6429" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6430" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6431" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6432" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6433" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6434" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6435" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6436" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6437" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6438" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6439" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6440" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6441" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6442" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6443" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6444" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6445" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6446" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6447" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6448" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6449" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6450" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6451" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6452" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6453" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6454" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6455" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6456" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6457" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6458" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6459" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6460" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6461" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6462" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6463" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6464" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6465
Bram Moolenaara6878372014-03-22 21:02:50 +01006466 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006467" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006468 " local normal-mode maps {{{3
6469 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6470 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6471 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6472 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6473 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6474 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6475 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6476 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6477 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6478 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6479 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6480" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006481 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6482 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6483 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006484 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006486 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6487 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6488 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6489 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6491 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6492 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6493 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6494 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6495 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6496 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6497 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6498 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6499 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6500 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6501 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6502 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006504 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006505 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6506 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6507 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6508 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6509 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006510 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006511 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006512 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6513 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006514 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6515 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6516 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006517 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006518 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006519 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6520 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006521 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006522 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006523 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6524 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6525 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006526 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6527 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006528
6529 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 +01006530 if !hasmapto('<Plug>NetrwHideEdit')
6531 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006532 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006533 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006534 if !hasmapto('<Plug>NetrwRefresh')
6535 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006536 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006537 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 +01006538 if s:didstarstar || !mapcheck("<s-down>","n")
6539 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006540 endif
6541 if s:didstarstar || !mapcheck("<s-up>","n")
6542 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006543 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006544 if !hasmapto('<Plug>NetrwTreeSqueeze')
6545 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006546 endif
6547 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006548 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6549 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006550 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6551 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6552 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6553 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6554 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6555 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6556 imap <buffer> <leftmouse> <Plug>ILeftmouse
6557 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006558 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6559 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6560 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6561 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6562 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006563 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006564 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6565 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006566 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006567 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6568 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6569 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6570 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6571 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6572 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6573 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006574 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6575
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006576 " support user-specified maps
6577 call netrw#UserMaps(1)
6578
Bram Moolenaar85850f32019-07-19 22:05:51 +02006579 else
6580 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006581" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006582 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006583 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6584 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6585 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6586 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6587 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6588 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6589 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6590 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6591 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6592 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6593 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6594" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006595 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6596 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6597 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6598 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6599 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6601 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6602 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006604 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6606 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6607 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6608 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6609 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6610 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6611 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6612 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6613 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6614 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6615 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006617 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6619 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6620 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6621 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6622 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6624 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6625 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6626 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006628 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6629 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006631 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 +01006632 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6633 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6634 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6635 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6636 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6637 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6638 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6639 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6640 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006641 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 if !hasmapto('<Plug>NetrwHideEdit')
6643 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006644 endif
6645 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6646 if !hasmapto('<Plug>NetrwRefresh')
6647 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006648 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006649 if !hasmapto('<Plug>NetrwTreeSqueeze')
6650 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006651 endif
6652 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006653
6654 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006655 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006656
6657 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6658 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006659 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006660 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006662 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006663 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006664 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006665 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006666 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006667 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006668 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006669 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6670 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6671 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006672 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006674 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6675 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006677 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6678 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6679 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6680 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6681 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6682 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6683 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006684 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006685
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006686 " support user-specified maps
6687 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006688 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006689
6690" call Dret("s:NetrwMaps")
6691endfun
6692
6693" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006694" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006695" If -buffer, the command is only available from within netrw buffers
6696" Otherwise, the command is available from any window, so long as netrw
6697" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006698fun! s:NetrwCommands(islocal)
6699" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6700
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006701 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6702 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006703 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 +01006704 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006705 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006706 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006707 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006708 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006709 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006710
6711" call Dret("s:NetrwCommands")
6712endfun
6713
6714" ---------------------------------------------------------------------
6715" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6716" glob()ing only works with local files
6717fun! s:NetrwMarkFiles(islocal,...)
6718" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006719 let curdir = s:NetrwGetCurdir(a:islocal)
6720 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006721 while i <= a:0
6722 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006723 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006724 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006726 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006727 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006728 else
6729 let mffiles= [a:{i}]
6730 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006731" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006732 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006733" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006734 call s:NetrwMarkFile(a:islocal,mffile)
6735 endfor
6736 let i= i + 1
6737 endwhile
6738" call Dret("s:NetrwMarkFiles")
6739endfun
6740
6741" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006742" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006743fun! s:NetrwMarkTarget(...)
6744" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6745 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006746 let curdir = s:NetrwGetCurdir(1)
6747 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006748 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006749 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6750 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006751 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006753 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6755 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006756 let svpos = winsaveview()
6757" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006758 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006759" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6760 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006761" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006762endfun
6763
6764" ---------------------------------------------------------------------
6765" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6766" mark and unmark files. If a markfile list exists,
6767" then the rename and delete functions will use it instead
6768" of whatever may happen to be under the cursor at that
6769" moment. When the mouse and gui are available,
6770" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006771"
6772" Creates two lists
6773" s:netrwmarkfilelist -- holds complete paths to all marked files
6774" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6775"
6776" Creates a marked file match string
6777" s:netrwmarfilemtch_# -- used with 2match to display marked files
6778"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006779" Creates a buffer version of islocal
6780" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006781fun! s:NetrwMarkFile(islocal,fname)
6782" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006783" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006784
6785 " sanity check
6786 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006787" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006788 return
6789 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006790 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006791
Bram Moolenaar97d62492012-11-15 21:28:22 +01006792 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006793 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006794 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006795 if a:fname =~ '\a$'
6796 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6797 else
6798 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6799 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006800
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006801 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006802 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006803" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6804" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6805" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006806 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006807
6808 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006809 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006810" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006811 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006813
6814 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006815 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006816" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006817 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6818 if s:netrwmarkfilelist_{curbufnr} == []
6819 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006821 call s:NetrwUnmarkList(curbufnr,curdir)
6822 else
6823 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006825 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006826 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006827 for fname in s:netrwmarkfilelist_{curbufnr}
6828 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006829 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006830 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006831 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006832 endif
6833 let first= 0
6834 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006835" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006836 endif
6837 endif
6838
6839 else
6840 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006841" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006843" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006844 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6846" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006847
6848 " build initial markfile matching pattern
6849 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006850 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006851 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006852 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006853 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855 endif
6856
6857 " handle global markfilelist
6858 if exists("s:netrwmarkfilelist")
6859 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6860 if index(s:netrwmarkfilelist,dname) == -1
6861 " append new filename to global markfilelist
6862 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006863" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006864 else
6865 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006866" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6867" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006868 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006869" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006870 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006871" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872 unlet s:netrwmarkfilelist
6873 endif
6874 endif
6875 else
6876 " initialize new global-directory markfilelist
6877 let s:netrwmarkfilelist= []
6878 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006879" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880 endif
6881
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006882 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006883 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6884 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6885" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6886 if exists("g:did_drchip_netrwlist_syntax")
6887 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6888 endif
6889 else
6890" " call Decho("2match none",'~'.expand("<slnum>"))
6891 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006894 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006895" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6896" 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 +00006897endfun
6898
6899" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006900" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6901" mA: move the argument list to marked file list (tomflist=1)
6902" Uses the global marked file list
6903fun! s:NetrwMarkFileArgList(islocal,tomflist)
6904" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6905
6906 let svpos = winsaveview()
6907" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6908 let curdir = s:NetrwGetCurdir(a:islocal)
6909 let curbufnr = bufnr("%")
6910
6911 if a:tomflist
6912 " mA: move argument list to marked file list
6913 while argc()
6914 let fname= argv(0)
6915" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6916 exe "argdel ".fnameescape(fname)
6917 call s:NetrwMarkFile(a:islocal,fname)
6918 endwhile
6919
6920 else
6921 " ma: move marked file list to argument list
6922 if exists("s:netrwmarkfilelist")
6923
6924 " for every filename in the marked list
6925 for fname in s:netrwmarkfilelist
6926" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6927 exe "argadd ".fnameescape(fname)
6928 endfor " for every file in the marked list
6929
6930 " unmark list and refresh
6931 call s:NetrwUnmarkList(curbufnr,curdir)
6932 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6933" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6934 NetrwKeepj call winrestview(svpos)
6935 endif
6936 endif
6937
6938" call Dret("s:NetrwMarkFileArgList")
6939endfun
6940
6941" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6943" compress/decompress files using the programs
6944" in g:netrw_compress and g:netrw_uncompress,
6945" using g:netrw_compress_suffix to know which to
6946" do. By default:
6947" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006948" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006949fun! s:NetrwMarkFileCompress(islocal)
6950" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006951 let svpos = winsaveview()
6952" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006953 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 let curbufnr = bufnr("%")
6955
Bram Moolenaarff034192013-04-24 18:51:19 +02006956 " sanity check
6957 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006958 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006959" call Dret("s:NetrwMarkFileCompress")
6960 return
6961 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006962" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006963
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006965
6966 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006968 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006969" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006970 if exists("g:netrw_decompress['".sfx."']")
6971 " fname has a suffix indicating that its compressed; apply associated decompression routine
6972 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006973" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006974 let exe= netrw#WinPath(exe)
6975 if a:islocal
6976 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006977 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006979 call system(exe." ".fname)
6980 if v:shell_error
6981 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006982 endif
6983 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006984 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6985 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006986 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006987
Bram Moolenaarff034192013-04-24 18:51:19 +02006988 endif
6989 unlet sfx
6990
Bram Moolenaar446cb832008-06-24 21:56:24 +00006991 if exists("exe")
6992 unlet exe
6993 elseif a:islocal
6994 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006995 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006996 if v:shell_error
6997 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6998 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006999 else
7000 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007001 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007002 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007003 endfor " for every file in the marked list
7004
Bram Moolenaar446cb832008-06-24 21:56:24 +00007005 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007006 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007007" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7008 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007009 endif
7010" call Dret("s:NetrwMarkFileCompress")
7011endfun
7012
7013" ---------------------------------------------------------------------
7014" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7015" If no marked files, then set up directory as the
7016" target. Currently does not support copying entire
7017" directories. Uses the local-buffer marked file list.
7018" Returns 1=success (used by NetrwMarkFileMove())
7019" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007020fun! s:NetrwMarkFileCopy(islocal,...)
7021" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7022
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007023 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007024 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007025 if b:netrw_curdir !~ '/$'
7026 if !exists("b:netrw_curdir")
7027 let b:netrw_curdir= curdir
7028 endif
7029 let b:netrw_curdir= b:netrw_curdir."/"
7030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007031
Bram Moolenaarff034192013-04-24 18:51:19 +02007032 " sanity check
7033 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007034 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007035" call Dret("s:NetrwMarkFileCopy")
7036 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007037 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007038" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007039
Bram Moolenaar446cb832008-06-24 21:56:24 +00007040 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007041 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042" call Dret("s:NetrwMarkFileCopy 0")
7043 return 0
7044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007045" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007046
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007047 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007048 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007049" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007050 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007051 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7052" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7053 return
7054 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007055
7056 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007057 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007058 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7059 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007060" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007061 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007062 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7063 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007064" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007065 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007066 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007067 let oldname = a:1
7068 else
7069 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007071 let s:recursive= 1
7072 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7073 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7074 if ret == 0
7075 break
7076 endif
7077 endfor
7078 unlet s:recursive
7079 call s:NetrwUnmarkList(curbufnr,curdir)
7080" call Dret("s:NetrwMarkFileCopy ".ret)
7081 return ret
7082 endif
7083
7084 call inputsave()
7085 let newname= input("Copy ".oldname." to : ",oldname,"file")
7086 call inputrestore()
7087 if newname == ""
7088" call Dret("s:NetrwMarkFileCopy 0")
7089 return 0
7090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007091 let args= s:ShellEscape(oldname)
7092 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007093 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007094 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7095 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007096 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007097 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007098 let args= substitute(args,'/','\\','g')
7099 let tgt = substitute(tgt, '/','\\','g')
7100 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007101 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7102 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7103 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7104 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7105" call Decho("args <".args.">",'~'.expand("<slnum>"))
7106" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007107 if isdirectory(s:NetrwFile(args))
7108" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007109 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007110" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007111 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007112 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7113 " contents to a target. One must append the source directory name to the target to get xcopy to
7114 " do the right thing.
7115 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007116" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007117 endif
7118 else
7119 let copycmd= g:netrw_localcopycmd
7120 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007121 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007122 let copycmd = substitute(copycmd,'\s.*$','','')
7123 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007124 let copycmd = netrw#WinPath(copycmd).copycmdargs
7125 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007126 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007127 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007128" call Decho("args <".args.">",'~'.expand("<slnum>"))
7129" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7130" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7131" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007132 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007133 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007134 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007135 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 +01007136 else
7137 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7138 endif
7139" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007140 return 0
7141 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142
7143 elseif a:islocal && !s:netrwmftgt_islocal
7144 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007146 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007147
7148 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007149 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007150" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007151 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007152
7153 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007154 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007155" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007156 let curdir = getcwd()
7157 let tmpdir = s:GetTempfile("")
7158 if tmpdir !~ '/'
7159 let tmpdir= curdir."/".tmpdir
7160 endif
7161 if exists("*mkdir")
7162 call mkdir(tmpdir)
7163 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007164 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007165 if v:shell_error != 0
7166 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 +01007167" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007168 return
7169 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007171 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007172 if s:NetrwLcd(tmpdir)
7173" call Dret("s:NetrwMarkFileCopy : lcd failure")
7174 return
7175 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007176 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007177 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007178 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007179 if getcwd() == tmpdir
7180 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007181 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007182 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007183 if s:NetrwLcd(curdir)
7184" call Dret("s:NetrwMarkFileCopy : lcd failure")
7185 return
7186 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007187 if delete(tmpdir,"d")
7188 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007189 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007190 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007191 if s:NetrwLcd(curdir)
7192" call Dret("s:NetrwMarkFileCopy : lcd failure")
7193 return
7194 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007195 endif
7196 endif
7197 endif
7198
7199 " -------
7200 " cleanup
7201 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007202" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007203 " remove markings from local buffer
7204 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007205" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7206" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7207" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7208" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7209" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7210" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7211 if exists("s:recursive")
7212" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7213 else
7214" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007215 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007216 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007217 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007218 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007219 else
7220 " refresh local and targets for fast browsing
7221 if !exists("s:recursive")
7222 " remove markings from local buffer
7223" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7224 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7225 endif
7226
7227 " refresh buffers
7228 if s:netrwmftgt_islocal
7229" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7230 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7231 endif
7232 if a:islocal && s:netrwmftgt != curdir
7233" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7234 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7235 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007236 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007237
Bram Moolenaar446cb832008-06-24 21:56:24 +00007238" call Dret("s:NetrwMarkFileCopy 1")
7239 return 1
7240endfun
7241
7242" ---------------------------------------------------------------------
7243" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7244" invoke vim's diff mode on the marked files.
7245" Either two or three files can be so handled.
7246" Uses the global marked file list.
7247fun! s:NetrwMarkFileDiff(islocal)
7248" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7249 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007250
Bram Moolenaarff034192013-04-24 18:51:19 +02007251 " sanity check
7252 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007253 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007254" call Dret("s:NetrwMarkFileDiff")
7255 return
7256 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007257 let curdir= s:NetrwGetCurdir(a:islocal)
7258" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007259
Bram Moolenaara6878372014-03-22 21:02:50 +01007260 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007262 for fname in s:netrwmarkfilelist
7263 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007264 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007265" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007266 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 diffthis
7268 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007269 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007270" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007271 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272 diffthis
7273 else
7274 break
7275 endif
7276 endfor
7277 call s:NetrwUnmarkList(curbufnr,curdir)
7278 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007279
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280" call Dret("s:NetrwMarkFileDiff")
7281endfun
7282
7283" ---------------------------------------------------------------------
7284" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7285" Uses global markfilelist
7286fun! s:NetrwMarkFileEdit(islocal)
7287" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7288
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007289 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007291
7292 " sanity check
7293 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007294 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007295" call Dret("s:NetrwMarkFileEdit")
7296 return
7297 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007298" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007299
Bram Moolenaar446cb832008-06-24 21:56:24 +00007300 if exists("s:netrwmarkfilelist_{curbufnr}")
7301 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007302 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007303 " unmark markedfile list
7304" call s:NetrwUnmarkList(curbufnr,curdir)
7305 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007306" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007307 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007308 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007309 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007310
Bram Moolenaar446cb832008-06-24 21:56:24 +00007311" call Dret("s:NetrwMarkFileEdit")
7312endfun
7313
7314" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007315" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007316fun! s:NetrwMarkFileQFEL(islocal,qfel)
7317" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7318 call s:NetrwUnmarkAll()
7319 let curbufnr= bufnr("%")
7320
7321 if !empty(a:qfel)
7322 for entry in a:qfel
7323 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007324" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007325 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007326" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007327 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7328 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7329 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7330 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007331" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007332 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7333 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007334" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007335 endif
7336 endfor
7337 echo "(use me to edit marked files)"
7338 else
7339 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7340 endif
7341
7342" call Dret("s:NetrwMarkFileQFEL")
7343endfun
7344
7345" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007346" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7347" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7348" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7349fun! s:NetrwMarkFileExe(islocal,enbloc)
7350" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007351 let svpos = winsaveview()
7352" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007353 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007354 let curbufnr = bufnr("%")
7355
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007356 if a:enbloc == 0
7357 " individually apply command to files, one at a time
7358 " sanity check
7359 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7360 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7361" call Dret("s:NetrwMarkFileExe")
7362 return
7363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007365
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 if exists("s:netrwmarkfilelist_{curbufnr}")
7367 " get the command
7368 call inputsave()
7369 let cmd= input("Enter command: ","","file")
7370 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007371" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007372 if cmd == ""
7373" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7374 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007376
7377 " apply command to marked files, individually. Substitute: filename -> %
7378 " If no %, then append a space and the filename to the command
7379 for fname in s:netrwmarkfilelist_{curbufnr}
7380 if a:islocal
7381 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007382 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007383 endif
7384 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007385 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007386 endif
7387 if cmd =~ '%'
7388 let xcmd= substitute(cmd,'%',fname,'g')
7389 else
7390 let xcmd= cmd.' '.fname
7391 endif
7392 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 let ret= system(xcmd)
7395 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007396" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007397 let ret= s:RemoteSystem(xcmd)
7398 endif
7399 if v:shell_error < 0
7400 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7401 break
7402 else
yasudac75dad02024-08-22 21:06:32 +02007403 if ret !=# ''
7404 echo "\n"
7405 " skip trailing new line
7406 echo ret[0:-2]
7407 else
7408 echo ret
7409 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007410 endif
7411 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007412
7413 " unmark marked file list
7414 call s:NetrwUnmarkList(curbufnr,curdir)
7415
7416 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007417 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007418" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7419 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007420 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007421 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007422 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007423
7424 else " apply command to global list of files, en bloc
7425
7426 call inputsave()
7427 let cmd= input("Enter command: ","","file")
7428 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007429" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007430 if cmd == ""
7431" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7432 return
7433 endif
7434 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007436 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007437 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007438 endif
7439 if a:islocal
7440 call system(cmd)
7441 if v:shell_error < 0
7442 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7443 endif
7444 else
7445 let ret= s:RemoteSystem(cmd)
7446 endif
7447 call s:NetrwUnmarkAll()
7448
7449 " refresh the listing
7450 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007451" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7452 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453
7454 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007455
Bram Moolenaar446cb832008-06-24 21:56:24 +00007456" call Dret("s:NetrwMarkFileExe")
7457endfun
7458
7459" ---------------------------------------------------------------------
7460" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7461" as the marked file(s) (toggles suffix presence)
7462" Uses the local marked file list.
7463fun! s:NetrwMarkHideSfx(islocal)
7464" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007465 let svpos = winsaveview()
7466" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007467 let curbufnr = bufnr("%")
7468
7469 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7470 if exists("s:netrwmarkfilelist_{curbufnr}")
7471
7472 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007473" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007474 " construct suffix pattern
7475 if fname =~ '\.'
7476 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7477 else
7478 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7479 endif
7480 " determine if its in the hiding list or not
7481 let inhidelist= 0
7482 if g:netrw_list_hide != ""
7483 let itemnum = 0
7484 let hidelist= split(g:netrw_list_hide,',')
7485 for hidepat in hidelist
7486 if sfxpat == hidepat
7487 let inhidelist= 1
7488 break
7489 endif
7490 let itemnum= itemnum + 1
7491 endfor
7492 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007494 if inhidelist
7495 " remove sfxpat from list
7496 call remove(hidelist,itemnum)
7497 let g:netrw_list_hide= join(hidelist,",")
7498 elseif g:netrw_list_hide != ""
7499 " append sfxpat to non-empty list
7500 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7501 else
7502 " set hiding list to sfxpat
7503 let g:netrw_list_hide= sfxpat
7504 endif
7505 endfor
7506
7507 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007509" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7510 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513 endif
7514
7515" call Dret("s:NetrwMarkHideSfx")
7516endfun
7517
7518" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007519" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007520" Uses the local marked-file list.
7521fun! s:NetrwMarkFileVimCmd(islocal)
7522" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007523 let svpos = winsaveview()
7524" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007525 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007526 let curbufnr = bufnr("%")
7527
Bram Moolenaarff034192013-04-24 18:51:19 +02007528 " sanity check
7529 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007531" call Dret("s:NetrwMarkFileVimCmd")
7532 return
7533 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007534" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007535
Bram Moolenaar15146672011-10-20 22:22:38 +02007536 if exists("s:netrwmarkfilelist_{curbufnr}")
7537 " get the command
7538 call inputsave()
7539 let cmd= input("Enter vim command: ","","file")
7540 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007541" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007542 if cmd == ""
7543" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7544 return
7545 endif
7546
7547 " apply command to marked files. Substitute: filename -> %
7548 " If no %, then append a space and the filename to the command
7549 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007550" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007551 if a:islocal
7552 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007553 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007555 exe cmd
7556 exe "sil! keepalt wq!"
7557 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007558" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007559 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007560 endif
7561 endfor
7562
7563 " unmark marked file list
7564 call s:NetrwUnmarkList(curbufnr,curdir)
7565
7566 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007567 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007568" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7569 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007570 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007572 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007573
Bram Moolenaar15146672011-10-20 22:22:38 +02007574" call Dret("s:NetrwMarkFileVimCmd")
7575endfun
7576
7577" ---------------------------------------------------------------------
7578" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7579" as the marked file(s) (toggles suffix presence)
7580" Uses the local marked file list.
7581fun! s:NetrwMarkHideSfx(islocal)
7582" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007583 let svpos = winsaveview()
7584" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007585 let curbufnr = bufnr("%")
7586
7587 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7588 if exists("s:netrwmarkfilelist_{curbufnr}")
7589
7590 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007591" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007592 " construct suffix pattern
7593 if fname =~ '\.'
7594 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7595 else
7596 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7597 endif
7598 " determine if its in the hiding list or not
7599 let inhidelist= 0
7600 if g:netrw_list_hide != ""
7601 let itemnum = 0
7602 let hidelist= split(g:netrw_list_hide,',')
7603 for hidepat in hidelist
7604 if sfxpat == hidepat
7605 let inhidelist= 1
7606 break
7607 endif
7608 let itemnum= itemnum + 1
7609 endfor
7610 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007611" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007612 if inhidelist
7613 " remove sfxpat from list
7614 call remove(hidelist,itemnum)
7615 let g:netrw_list_hide= join(hidelist,",")
7616 elseif g:netrw_list_hide != ""
7617 " append sfxpat to non-empty list
7618 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7619 else
7620 " set hiding list to sfxpat
7621 let g:netrw_list_hide= sfxpat
7622 endif
7623 endfor
7624
7625 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007626 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007627" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7628 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007629 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007630 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007631 endif
7632
7633" call Dret("s:NetrwMarkHideSfx")
7634endfun
7635
7636" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007637" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7638" Uses the global markfilelist
7639fun! s:NetrwMarkFileGrep(islocal)
7640" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007641 let svpos = winsaveview()
7642" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007643 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007645
7646 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007647" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007648 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007649" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007650 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007651 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007653 let netrwmarkfilelist= "*"
7654 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007655
Bram Moolenaarff034192013-04-24 18:51:19 +02007656 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007657" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007658 call inputsave()
7659 let pat= input("Enter pattern: ","")
7660 call inputrestore()
7661 let patbang = ""
7662 if pat =~ '^!'
7663 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007665 endif
7666 if pat =~ '^\i'
7667 let pat = escape(pat,'/')
7668 let pat = '/'.pat.'/'
7669 else
7670 let nonisi = pat[0]
7671 endif
7672
7673 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007675 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007676 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007677 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007678 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007679" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7680 return
7681 endtry
7682 echo "(use :cn, :cp to navigate, :Rex to return)"
7683
7684 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007685" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7686 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007687
7688 if exists("nonisi")
7689 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007690" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007691 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007692 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007693 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007694 endif
7695
7696" call Dret("s:NetrwMarkFileGrep")
7697endfun
7698
7699" ---------------------------------------------------------------------
7700" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7701" uses the global marked file list
7702" s:netrwmfloc= 0: target directory is remote
7703" = 1: target directory is local
7704fun! s:NetrwMarkFileMove(islocal)
7705" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007706 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007707 let curbufnr = bufnr("%")
7708
7709 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007710 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007711 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007712" call Dret("s:NetrwMarkFileMove")
7713 return
7714 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007715" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007716
Bram Moolenaar446cb832008-06-24 21:56:24 +00007717 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007718 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007719" call Dret("s:NetrwMarkFileCopy 0")
7720 return 0
7721 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007722" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007723
7724 if a:islocal && s:netrwmftgt_islocal
7725 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007726" call Decho("move from local to local",'~'.expand("<slnum>"))
7727" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007728 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007729 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7730" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7731 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007732 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007733 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007734" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007735 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007736 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007737" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007738 if g:netrw_localmovecmd =~ '\s'
7739 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7740 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7741 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007742" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007743 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007744 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007745" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007746 endif
7747 else
7748 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007749" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007751 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007752 if g:netrw_keepdir
7753 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7754 let fname= b:netrw_curdir."/".fname
7755 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007756 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007757 let fname= substitute(fname,'/','\\','g')
7758 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007759" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007760 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007761 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007762 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007763 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 +01007764 else
7765 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7766 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007767 break
7768 endif
7769 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007770
7771 elseif a:islocal && !s:netrwmftgt_islocal
7772 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773" call Decho("move from local to remote",'~'.expand("<slnum>"))
7774" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007775 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007776 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007777" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 for fname in mflist
7779 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7780 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7781 endfor
7782 unlet mflist
7783
7784 elseif !a:islocal && s:netrwmftgt_islocal
7785 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007786" call Decho("move from remote to local",'~'.expand("<slnum>"))
7787" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007788 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007789 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007790" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007791 for fname in mflist
7792 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7793 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7794 endfor
7795 unlet mflist
7796
7797 elseif !a:islocal && !s:netrwmftgt_islocal
7798 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007799" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7800" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007802 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007803" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007804 for fname in mflist
7805 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7806 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7807 endfor
7808 unlet mflist
7809 endif
7810
7811 " -------
7812 " cleanup
7813 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007815
7816 " remove markings from local buffer
7817 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7818
7819 " refresh buffers
7820 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007821" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007822 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823 endif
7824 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007826 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007827 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007828 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007830 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007831 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007832
Bram Moolenaar446cb832008-06-24 21:56:24 +00007833" call Dret("s:NetrwMarkFileMove")
7834endfun
7835
7836" ---------------------------------------------------------------------
7837" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7838" using the hardcopy command. Local marked-file list only.
7839fun! s:NetrwMarkFilePrint(islocal)
7840" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7841 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007842
7843 " sanity check
7844 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007845 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007846" call Dret("s:NetrwMarkFilePrint")
7847 return
7848 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7850 let curdir= s:NetrwGetCurdir(a:islocal)
7851
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852 if exists("s:netrwmarkfilelist_{curbufnr}")
7853 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007854 call s:NetrwUnmarkList(curbufnr,curdir)
7855 for fname in netrwmarkfilelist
7856 if a:islocal
7857 if g:netrw_keepdir
7858 let fname= s:ComposePath(curdir,fname)
7859 endif
7860 else
7861 let fname= curdir.fname
7862 endif
7863 1split
7864 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007865" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007866 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007868 hardcopy
7869 q
7870 endfor
7871 2match none
7872 endif
7873" call Dret("s:NetrwMarkFilePrint")
7874endfun
7875
7876" ---------------------------------------------------------------------
7877" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7878" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007879" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880fun! s:NetrwMarkFileRegexp(islocal)
7881" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7882
7883 " get the regular expression
7884 call inputsave()
7885 let regexp= input("Enter regexp: ","","file")
7886 call inputrestore()
7887
7888 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007889 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007890" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007891 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007892" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007893 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007894 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007895 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007896 else
7897 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007898 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007899 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007900" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007901
7902 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007903 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007904 if fname =~ '^'.fnameescape(curdir)
7905" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7906 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7907 else
7908" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7909 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7910 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007911 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912
7913 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915
7916 " convert displayed listing into a filelist
7917 let eikeep = &ei
7918 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007919 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007920 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007923 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007924 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007925 sil NetrwKeepj norm! "ap
7926 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007928 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007929 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007930 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007931 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007932 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007933 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007934 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007935 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007937 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7938 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007939 call histdel("/",-1)
7940 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941 endif
7942 " convert regexp into the more usual glob-style format
7943 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007944" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007945 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007946 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007947 let filelist= getline(1,line("$"))
7948 q!
7949 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007950 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 endfor
7952 unlet filelist
7953 let @a = areg
7954 let &ei = eikeep
7955 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007956 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957
7958" call Dret("s:NetrwMarkFileRegexp")
7959endfun
7960
7961" ---------------------------------------------------------------------
7962" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7963" Uses the local marked file list.
7964fun! s:NetrwMarkFileSource(islocal)
7965" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7966 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007967
7968 " sanity check
7969 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007970 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007971" call Dret("s:NetrwMarkFileSource")
7972 return
7973 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007974" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7975 let curdir= s:NetrwGetCurdir(a:islocal)
7976
Bram Moolenaar446cb832008-06-24 21:56:24 +00007977 if exists("s:netrwmarkfilelist_{curbufnr}")
7978 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979 call s:NetrwUnmarkList(curbufnr,curdir)
7980 for fname in netrwmarkfilelist
7981 if a:islocal
7982 if g:netrw_keepdir
7983 let fname= s:ComposePath(curdir,fname)
7984 endif
7985 else
7986 let fname= curdir.fname
7987 endif
7988 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007989" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007990 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 endfor
7992 2match none
7993 endif
7994" call Dret("s:NetrwMarkFileSource")
7995endfun
7996
7997" ---------------------------------------------------------------------
7998" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7999" Uses the global markfilelist
8000fun! s:NetrwMarkFileTag(islocal)
8001" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008002 let svpos = winsaveview()
8003" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 let curbufnr = bufnr("%")
8006
Bram Moolenaarff034192013-04-24 18:51:19 +02008007 " sanity check
8008 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008009 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008010" call Dret("s:NetrwMarkFileTag")
8011 return
8012 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008013" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008014
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008016" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8017 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 call s:NetrwUnmarkAll()
8019
8020 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008021
8022" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8023 call system(g:netrw_ctags." ".netrwmarkfilelist)
8024 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8026 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008027
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008029 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008030 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008031 let curdir= b:netrw_curdir
8032 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008033 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008037 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 wq!
8039 endif
8040 2match none
8041 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008042" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8043 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008044 endif
8045
8046" call Dret("s:NetrwMarkFileTag")
8047endfun
8048
8049" ---------------------------------------------------------------------
8050" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008051" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008052" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008054" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008056" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8057 let svpos = winsaveview()
8058" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008059 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 let hadtgt = exists("s:netrwmftgt")
8061 if !exists("w:netrw_bannercnt")
8062 let w:netrw_bannercnt= b:netrw_bannercnt
8063 endif
8064
8065 " set up target
8066 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008067" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008068 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8069 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008070" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008071 unlet s:netrwmftgt s:netrwmftgt_islocal
8072 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008073 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008074 endif
8075 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008076" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8077 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008078" call Dret("s:NetrwMarkFileTgt : removed target")
8079 return
8080 else
8081 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008082" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008083 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084
8085 else
8086 " get word under cursor.
8087 " * If directory, use it for the target.
8088 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008089" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 let curword= s:NetrwGetWord()
8091 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008092 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008093 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008094" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008095 elseif !a:islocal && tgtdir =~ '/$'
8096 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008097" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 else
8099 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008100" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008101 endif
8102 endif
8103 if a:islocal
8104 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8105 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008106" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008107 endif
8108 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008109 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8111 endif
8112 let s:netrwmftgt_islocal= a:islocal
8113
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008114 " need to do refresh so that the banner will be updated
8115 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008116 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008117" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008118 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008120" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008121 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008122 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8123 else
8124 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8125 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008126" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8127 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008129 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 endif
8131
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008132" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8133" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008134" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8135endfun
8136
8137" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008138" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8139fun! s:NetrwGetCurdir(islocal)
8140" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8141
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008142 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008143 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8144" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8145 elseif !exists("b:netrw_curdir")
8146 let b:netrw_curdir= getcwd()
8147" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8148 endif
8149
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008150" 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 +01008151 if b:netrw_curdir !~ '\<\a\{3,}://'
8152 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008153" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008154 if g:netrw_keepdir == 0
8155 call s:NetrwLcd(curdir)
8156 endif
8157 endif
8158
8159" call Dret("s:NetrwGetCurdir <".curdir.">")
8160 return b:netrw_curdir
8161endfun
8162
8163" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008164" s:NetrwOpenFile: query user for a filename and open it {{{2
8165fun! s:NetrwOpenFile(islocal)
8166" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008167 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008168 call inputsave()
8169 let fname= input("Enter filename: ")
8170 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008171" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8172
8173 " determine if Lexplore is in use
8174 if exists("t:netrw_lexbufnr")
8175 " check if t:netrw_lexbufnr refers to a netrw window
8176" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8177 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8178 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8179" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8180 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8181 exe "NetrwKeepj e ".fnameescape(fname)
8182 let @@= ykeep
8183" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8184 endif
8185 endif
8186
8187 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008188 if fname !~ '[/\\]'
8189 if exists("b:netrw_curdir")
8190 if exists("g:netrw_quiet")
8191 let netrw_quiet_keep = g:netrw_quiet
8192 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193 let g:netrw_quiet = 1
8194 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008195 let s:rexposn_{bufnr("%")}= winsaveview()
8196" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008197 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008198 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008199 else
8200 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8201 endif
8202 if exists("netrw_quiet_keep")
8203 let g:netrw_quiet= netrw_quiet_keep
8204 else
8205 unlet g:netrw_quiet
8206 endif
8207 endif
8208 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008209 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008210 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008211 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008212" call Dret("s:NetrwOpenFile")
8213endfun
8214
8215" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8217" For the mapping to this function be made via
8218" netrwPlugin, you'll need to have had
8219" g:netrw_usetab set to non-zero.
8220fun! netrw#Shrink()
8221" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8222 let curwin = winnr()
8223 let wiwkeep = &wiw
8224 set wiw=1
8225
8226 if &ft == "netrw"
8227 if winwidth(0) > g:netrw_wiw
8228 let t:netrw_winwidth= winwidth(0)
8229 exe "vert resize ".g:netrw_wiw
8230 wincmd l
8231 if winnr() == curwin
8232 wincmd h
8233 endif
8234" call Decho("vert resize 0",'~'.expand("<slnum>"))
8235 else
8236 exe "vert resize ".t:netrw_winwidth
8237" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8238 endif
8239
8240 elseif exists("t:netrw_lexbufnr")
8241 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8242 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8243 let t:netrw_winwidth= winwidth(0)
8244 exe "vert resize ".g:netrw_wiw
8245 wincmd l
8246 if winnr() == curwin
8247 wincmd h
8248 endif
8249" call Decho("vert resize 0",'~'.expand("<slnum>"))
8250 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8251 exe "vert resize ".t:netrw_winwidth
8252" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8253 else
8254 call netrw#Lexplore(0,0)
8255 endif
8256
8257 else
8258 call netrw#Lexplore(0,0)
8259 endif
8260 let wiw= wiwkeep
8261
8262" call Dret("netrw#Shrink")
8263endfun
8264
8265" ---------------------------------------------------------------------
8266" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8267fun! s:NetSortSequence(islocal)
8268" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8269
8270 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008271 let svpos= winsaveview()
8272" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008273 call inputsave()
8274 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8275 call inputrestore()
8276
8277 " refresh the listing
8278 let g:netrw_sort_sequence= newsortseq
8279 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008280" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8281 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008282 let @@= ykeep
8283
8284" call Dret("NetSortSequence")
8285endfun
8286
8287" ---------------------------------------------------------------------
8288" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8289" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008290" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008291fun! s:NetrwUnmarkList(curbufnr,curdir)
8292" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8293
8294 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008295 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008296 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8297 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8298 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8299 call remove(s:netrwmarkfilelist,idx) " remove from global list
8300 endfor
8301 if s:netrwmarkfilelist == []
8302 unlet s:netrwmarkfilelist
8303 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008304
Bram Moolenaar446cb832008-06-24 21:56:24 +00008305 " getting rid of the local marked-file lists is easy
8306 unlet s:netrwmarkfilelist_{a:curbufnr}
8307 endif
8308 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8309 unlet s:netrwmarkfilemtch_{a:curbufnr}
8310 endif
8311 2match none
8312" call Dret("s:NetrwUnmarkList")
8313endfun
8314
8315" ---------------------------------------------------------------------
8316" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8317fun! s:NetrwUnmarkAll()
8318" call Dfunc("s:NetrwUnmarkAll()")
8319 if exists("s:netrwmarkfilelist")
8320 unlet s:netrwmarkfilelist
8321 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008322 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008323 2match none
8324" call Dret("s:NetrwUnmarkAll")
8325endfun
8326
8327" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008328" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008329fun! s:NetrwUnmarkAll2()
8330" call Dfunc("s:NetrwUnmarkAll2()")
8331 redir => netrwmarkfilelist_let
8332 let
8333 redir END
8334 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008335 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008336 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8337 for flist in netrwmarkfilelist_list
8338 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8339 unlet s:netrwmarkfilelist_{curbufnr}
8340 unlet s:netrwmarkfilemtch_{curbufnr}
8341 endfor
8342" call Dret("s:NetrwUnmarkAll2")
8343endfun
8344
8345" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008346" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8347"
8348" Marked files are in two types of lists:
8349" s:netrwmarkfilelist -- holds complete paths to all marked files
8350" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8351"
8352" Marked files suitable for use with 2match are in:
8353" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008354fun! s:NetrwUnMarkFile(islocal)
8355" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008356 let svpos = winsaveview()
8357" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008358 let curbufnr = bufnr("%")
8359
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008360 " unmark marked file list
8361 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8362 if exists("s:netrwmarkfilelist")
8363" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008364 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008365 endif
8366
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008367 let ibuf= 1
8368 while ibuf < bufnr("$")
8369 if exists("s:netrwmarkfilelist_".ibuf)
8370 unlet s:netrwmarkfilelist_{ibuf}
8371 unlet s:netrwmarkfilemtch_{ibuf}
8372 endif
8373 let ibuf = ibuf + 1
8374 endwhile
8375 2match none
8376
Bram Moolenaar446cb832008-06-24 21:56:24 +00008377" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008378"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8379call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380" call Dret("s:NetrwUnMarkFile")
8381endfun
8382
8383" ---------------------------------------------------------------------
8384" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8385fun! s:NetrwMenu(domenu)
8386
8387 if !exists("g:NetrwMenuPriority")
8388 let g:NetrwMenuPriority= 80
8389 endif
8390
Bram Moolenaaradc21822011-04-01 18:03:16 +02008391 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008392" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8393
8394 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008396 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008397 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8398 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8399 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8400 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8401 if g:netrw_dirhistmax > 0
8402 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8403 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8404 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8405 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8406 else
8407 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8408 endif
8409 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8410 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8411 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8412 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8413 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8414 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8415 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8416 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8417 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8418 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8419 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8420 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8421 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8422 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8423 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 +01008424 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 +02008425 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8426 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8427 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8428 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8429 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8430 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8431 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8432 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8433 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8434 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8435 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8436 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8437 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8438 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8439 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8440 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8441 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8442 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8443 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8444 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8445 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8446 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8447 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8448 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8449 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8450 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8451 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8452 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8453 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8454 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>'
8455 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>'
8456 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>'
8457 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8458 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>'
8459 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>'
8460 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 +01008461 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 +02008462 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008465 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8466 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008467
8468 elseif !a:domenu
8469 let s:netrwcnt = 0
8470 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008471 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008472 exe curwin."wincmd w"
8473
8474 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008475" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008476 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008477" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008478 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479 endif
8480 endif
8481" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008482 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008483 endif
8484
8485endfun
8486
8487" ---------------------------------------------------------------------
8488" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8489" Used by the O maps (as <SID>NetrwObtain())
8490fun! s:NetrwObtain(islocal)
8491" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8492
Bram Moolenaar97d62492012-11-15 21:28:22 +01008493 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008494 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008495 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008496 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8498 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008499 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008501 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008502
8503" call Dret("NetrwObtain")
8504endfun
8505
8506" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8508" If there's only one window, then the window will first be split.
8509" Returns:
8510" choice = 0 : didn't have to choose
8511" choice = 1 : saved modified file in window first
8512" choice = 2 : didn't save modified file, opened window
8513" choice = 3 : cancel open
8514fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008515" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008516
Bram Moolenaar97d62492012-11-15 21:28:22 +01008517 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008518 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008519 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008520" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008521
8522 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008523 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008524 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008525" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8526" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8527 let curword = s:NetrwGetWord()
8528 let choice = 0
8529 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8530" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008531 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008532" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008533 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008534" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008535" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008536" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008537
Bram Moolenaar8d043172014-01-23 14:24:41 +01008538 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008539 if lastwinnr == 1
8540 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008541" 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 +02008542 " g:netrw_preview=0: preview window shown in a horizontally split window
8543 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008544 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008545 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008546 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008547" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008548 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008549 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008550 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008551 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008552" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008553 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008554 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008555 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008556" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008557
8558 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008559" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008560 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008561" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008562 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008563" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008564 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008565" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008567" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008568" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008569" call Decho("COMBAK#12: mod=".&mod)
8570
8571 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8572 " whoops -- user trying to open file in the Lexplore window.
8573 " Use Lexplore's opening-file window instead.
8574" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8575" exe g:netrw_chgwin."wincmd w"
8576 wincmd p
8577 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8578 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008579
8580 " prevwinnr: the window number of the "prev" window
8581 " prevbufnr: the buffer number of the buffer in the "prev" window
8582 " bnrcnt : the qty of windows open on the "prev" buffer
8583 let prevwinnr = winnr()
8584 let prevbufnr = bufnr("%")
8585 let prevbufname = bufname("%")
8586 let prevmod = &mod
8587 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008588" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008589 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008590" 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 +01008591" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008592
8593 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 " and it doesn't appear in any other extant window, then ask the
8595 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008596 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008597" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008598 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008599" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008600 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008601" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008602
8603 if bnrcnt == 1 && &hidden == 0
8604 " only one copy of the modified buffer in a window, and
8605 " hidden not set, so overwriting will lose the modified file. Ask first...
8606 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008607" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008608 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008609" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610
8611 if choice == 1
8612 " Yes -- write file & then browse
8613 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008614 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008616 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008617 exe origwin."wincmd w"
8618 let &ei = eikeep
8619 let @@ = ykeep
8620" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 return choice
8622 endif
8623
8624 elseif choice == 2
8625 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008627 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628
8629 else
8630 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008631" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632 exe origwin."wincmd w"
8633 let &ei= eikeep
8634 let @@ = ykeep
8635" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 return choice
8637 endif
8638 endif
8639 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008640 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008641 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008642" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643
8644 " restore b:netrw_curdir (window split/enew may have lost it)
8645 let b:netrw_curdir= curdir
8646 if a:islocal < 2
8647 if a:islocal
8648 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8649 else
8650 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8651 endif
8652 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008653 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008654" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008655 return choice
8656endfun
8657
8658" ---------------------------------------------------------------------
8659" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8660" Always assumed to be local -> remote
8661" call s:NetrwUpload(filename, target)
8662" call s:NetrwUpload(filename, target, fromdirectory)
8663fun! s:NetrwUpload(fname,tgt,...)
8664" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8665
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008666 if a:tgt =~ '^\a\{3,}://'
8667 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 else
8669 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008671" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672
8673 if a:0 > 0
8674 let fromdir= a:1
8675 else
8676 let fromdir= getcwd()
8677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008678" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008679
8680 if type(a:fname) == 1
8681 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008682" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008683 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008684" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8685 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8686" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008687 if a:tgt =~ '/$'
8688 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008689" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008690 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008691 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008692" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008693 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008694" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008695 endif
8696 q!
8697
8698 elseif type(a:fname) == 3
8699 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701 let curdir= getcwd()
8702 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008703 if s:NetrwLcd(fromdir)
8704" call Dret("s:NetrwUpload : lcd failure")
8705 return
8706 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008707 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008708 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 if exists("g:netrw_port") && g:netrw_port != ""
8710 let useport= " ".g:netrw_scpport." ".g:netrw_port
8711 else
8712 let useport= ""
8713 endif
8714 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8715 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008716 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 +02008717 if s:NetrwLcd(curdir)
8718" call Dret("s:NetrwUpload : lcd failure")
8719 return
8720 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721
8722 elseif a:tgt =~ '^ftp:'
8723 call s:NetrwMethod(a:tgt)
8724
8725 if b:netrw_method == 2
8726 " handle uploading a list of files via ftp+.netrc
8727 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008728 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008729" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008731 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008732" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008733
8734 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008735 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008736" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737 endif
8738
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008739 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008740" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008741
Bram Moolenaaradc21822011-04-01 18:03:16 +02008742 if tgtdir == ""
8743 let tgtdir= '/'
8744 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008745 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008746" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008747
8748 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008749 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8750" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008751 endfor
8752
8753 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008754 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 +00008755 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008756" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8757 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008758 endif
8759 " 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 +01008760 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008761 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8763 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8764 else
8765 bw!|q
8766 endif
8767
8768 elseif b:netrw_method == 3
8769 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8770 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008771 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008773 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774
8775 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008776 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008777" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008779 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008780" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 endif
8782
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008783 if exists("g:netrw_uid") && g:netrw_uid != ""
8784 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008785 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008787 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008788 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008789 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008790" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008791 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008792 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 endif
8796
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008797 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008798" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008799
8800 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008801 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803 endif
8804
8805 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008806 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 endif
8809
8810 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008811 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008812" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813 endfor
8814
8815 " perform ftp:
8816 " -i : turns off interactive prompting from ftp
8817 " -n unix : DON'T use <.netrc>, even though it exists
8818 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008819 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008820 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821 " 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 +01008822 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008823 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8825 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008826 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8828 let &debug = debugkeep
8829 let mod = 1
8830 else
8831 bw!|q
8832 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008833 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008834" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008835 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 endif
8837 else
8838 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8839 endif
8840 endif
8841
8842" call Dret("s:NetrwUpload")
8843endfun
8844
8845" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008846" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008847fun! s:NetrwPreview(path) range
8848" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008849" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8850" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008851 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008852 NetrwKeepj call s:NetrwOptionsSave("s:")
8853 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8854 NetrwKeepj call s:NetrwOptionsSafe(1)
8855 else
8856 NetrwKeepj call s:NetrwOptionsSafe(0)
8857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008859" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008860 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008861" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8862 if g:netrw_preview
8863 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008864 let pvhkeep = &pvh
8865 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8866 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008867" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8868 else
8869 " horizontal split
8870 let pvhkeep = &pvh
8871 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8872 let &pvh = winheight(0) - winsz
8873" 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 +02008874 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008875 " g:netrw_preview g:netrw_alto
8876 " 1 : vert 1: top -- preview window is vertically split off and on the left
8877 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8878 " 0 : 1: top -- preview window is horizontally split off and on the top
8879 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8880 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008881 " 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 +02008882 " the BufEnter event set up in netrwPlugin.vim
8883" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8884 let eikeep = &ei
8885 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008886 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008887 let &ei= eikeep
8888" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008889 if exists("pvhkeep")
8890 let &pvh= pvhkeep
8891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008892 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008893 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 endif
8895 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008896 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 +00008897 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008898 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008899 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008900" call Dret("NetrwPreview")
8901endfun
8902
8903" ---------------------------------------------------------------------
8904" s:NetrwRefresh: {{{2
8905fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008906" 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 +00008907 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008908 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008909" call Decho("setl ma noro",'~'.expand("<slnum>"))
8910" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008911 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008912 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8913 if !exists("w:netrw_treetop")
8914 if exists("b:netrw_curdir")
8915 let w:netrw_treetop= b:netrw_curdir
8916 else
8917 let w:netrw_treetop= getcwd()
8918 endif
8919 endif
8920 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8921 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008922
8923 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008924 let screenposn = winsaveview()
8925" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008926
8927" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8928" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8929 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008931 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008933 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008935
8936 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008937" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8938 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008939
8940 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8942 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8943" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8944 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8945 else
8946" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8947 2match none
8948 endif
8949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008950
Bram Moolenaar97d62492012-11-15 21:28:22 +01008951" restore
8952 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008953" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008954endfun
8955
8956" ---------------------------------------------------------------------
8957" s:NetrwRefreshDir: refreshes a directory by name {{{2
8958" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008959" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008961" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 if g:netrw_fastbrowse == 0
8963 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008964" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008965 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008966" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008967
8968 if tgtwin > 0
8969 " tgtwin is being displayed, so refresh it
8970 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008971" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008972 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008973 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008974 exe curwin."wincmd w"
8975
8976 elseif bufnr(a:dirname) > 0
8977 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008978" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8979 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008980 endif
8981
8982 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008983" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008984 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008985 endif
8986" call Dret("s:NetrwRefreshDir")
8987endfun
8988
8989" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008990" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8991" window number to do its editing in.
8992" Supports [count]C where the count, if present, is used to specify
8993" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008994fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008995" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008996 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008997" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008998 if a:1 == "" " :NetrwC win#
8999 let g:netrw_chgwin= winnr()
9000 else " :NetrwC
9001 let g:netrw_chgwin= a:1
9002 endif
9003 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009004 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009005 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009006 let g:netrw_chgwin= winnr()
9007 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009008 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009009" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009010endfun
9011
9012" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009013" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9014" What this function does is to compute a priority for the patterns
9015" in the g:netrw_sort_sequence. It applies a substitute to any
9016" "files" that satisfy each pattern, putting the priority / in
9017" front. An "*" pattern handles the default priority.
9018fun! s:NetrwSetSort()
9019" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009020 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021 if w:netrw_liststyle == s:LONGLIST
9022 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9023 else
9024 let seqlist = g:netrw_sort_sequence
9025 endif
9026 " sanity check -- insure that * appears somewhere
9027 if seqlist == ""
9028 let seqlist= '*'
9029 elseif seqlist !~ '\*'
9030 let seqlist= seqlist.',*'
9031 endif
9032 let priority = 1
9033 while seqlist != ""
9034 if seqlist =~ ','
9035 let seq = substitute(seqlist,',.*$','','e')
9036 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9037 else
9038 let seq = seqlist
9039 let seqlist = ""
9040 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009042 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009043 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009044 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009046 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009048" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049
9050 " sanity check
9051 if w:netrw_bannercnt > line("$")
9052 " apparently no files were left after a Hiding pattern was used
9053" call Dret("SetSort : no files left after hiding")
9054 return
9055 endif
9056 if seq == '*'
9057 let starpriority= spriority
9058 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009059 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009060 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061 " sometimes multiple sorting patterns will match the same file or directory.
9062 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9064 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 endif
9066 let priority = priority + 1
9067 endwhile
9068 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9070 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 endif
9072
9073 " Following line associated with priority -- items that satisfy a priority
9074 " pattern get prefixed by ###/ which permits easy sorting by priority.
9075 " Sometimes files can satisfy multiple priority patterns -- only the latest
9076 " priority pattern needs to be retained. So, at this point, these excess
9077 " priority prefixes need to be removed, but not directories that happen to
9078 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009079 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9080 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009081 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009082
9083" call Dret("SetSort")
9084endfun
9085
Bram Moolenaarff034192013-04-24 18:51:19 +02009086" ---------------------------------------------------------------------
9087" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9088" Implements [count]Tb (bookhist<b>)
9089" [count]Th (bookhist<h>)
9090" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009091fun! s:NetrwSetTgt(islocal,bookhist,choice)
9092" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009093
9094 if a:bookhist == 'b'
9095 " supports choosing a bookmark as a target using a qb-generated list
9096 let choice= a:choice - 1
9097 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009098 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009099 else
9100 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9101 endif
9102
9103 elseif a:bookhist == 'h'
9104 " supports choosing a history stack entry as a target using a qb-generated list
9105 let choice= (a:choice % g:netrw_dirhistmax) + 1
9106 if exists("g:netrw_dirhist_".choice)
9107 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009108 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009109 else
9110 echomsg "Sorry, history#".a:choice." not available!"
9111 endif
9112 endif
9113
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009114 " refresh the display
9115 if !exists("b:netrw_curdir")
9116 let b:netrw_curdir= getcwd()
9117 endif
9118 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9119
Bram Moolenaarff034192013-04-24 18:51:19 +02009120" call Dret("s:NetrwSetTgt")
9121endfun
9122
Bram Moolenaar446cb832008-06-24 21:56:24 +00009123" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009124" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009125fun! s:NetrwSortStyle(islocal)
9126" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009127 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009128 let svpos= winsaveview()
9129" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009130
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009131 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 +01009132 NetrwKeepj norm! 0
9133 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009134" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9135 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136
9137" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9138endfun
9139
9140" ---------------------------------------------------------------------
9141" s:NetrwSplit: mode {{{2
9142" =0 : net and o
9143" =1 : net and t
9144" =2 : net and v
9145" =3 : local and o
9146" =4 : local and t
9147" =5 : local and v
9148fun! s:NetrwSplit(mode)
9149" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9150
Bram Moolenaar97d62492012-11-15 21:28:22 +01009151 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 call s:SaveWinVars()
9153
9154 if a:mode == 0
9155 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009156 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009157 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009158" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009159 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 NetrwKeepj call s:RestoreWinVars()
9162 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009163 unlet s:didsplit
9164
9165 elseif a:mode == 1
9166 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009167 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009168" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009169 tabnew
9170 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009171 NetrwKeepj call s:RestoreWinVars()
9172 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009173 unlet s:didsplit
9174
9175 elseif a:mode == 2
9176 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009177 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009178 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009179" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009180 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009181 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009182 NetrwKeepj call s:RestoreWinVars()
9183 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009184 unlet s:didsplit
9185
9186 elseif a:mode == 3
9187 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009188 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009189 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009190" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009191 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009193 NetrwKeepj call s:RestoreWinVars()
9194 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009195 unlet s:didsplit
9196
9197 elseif a:mode == 4
9198 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009199 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009200 let eikeep = &ei
9201 let netrw_winnr = winnr()
9202 let netrw_line = line(".")
9203 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009204 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009205 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009206 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009207 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9208 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009209 let &ei = eikeep
9210 let netrw_curdir = s:NetrwTreeDir(0)
9211" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009212 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009213 let b:netrw_curdir = netrw_curdir
9214 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009215 NetrwKeepj call s:RestoreWinVars()
9216 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009217 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009218 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009219 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9220 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009221 let &ei= eikeep
9222 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009223 unlet s:didsplit
9224
9225 elseif a:mode == 5
9226 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009227 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009228 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009229" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009230 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009231 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009232 NetrwKeepj call s:RestoreWinVars()
9233 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009234 unlet s:didsplit
9235
9236 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009237 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009238 endif
9239
Bram Moolenaar97d62492012-11-15 21:28:22 +01009240 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241" call Dret("s:NetrwSplit")
9242endfun
9243
9244" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009245" s:NetrwTgtMenu: {{{2
9246fun! s:NetrwTgtMenu()
9247 if !exists("s:netrw_menucnt")
9248 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009250" call Dfunc("s:NetrwTgtMenu()")
9251
9252 " the following test assures that gvim is running, has menus available, and has menus enabled.
9253 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9254 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009255" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009256 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9257 endif
9258 if !exists("s:netrw_initbookhist")
9259 call s:NetrwBookHistRead()
9260 endif
9261
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262 " try to cull duplicate entries
9263 let tgtdict={}
9264
Bram Moolenaarff034192013-04-24 18:51:19 +02009265 " target bookmarked places
9266 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009267" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009268 let cnt= 1
9269 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270 if has_key(tgtdict,bmd)
9271 let cnt= cnt + 1
9272 continue
9273 endif
9274 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009275 let ebmd= escape(bmd,g:netrw_menu_escape)
9276 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009277" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009278 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 +02009279 let cnt= cnt + 1
9280 endfor
9281 endif
9282
9283 " target directory browsing history
9284 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009285" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009286 let histcnt = 1
9287 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009288 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009289 if exists("g:netrw_dirhist_{histcnt}")
9290 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291 if has_key(tgtdict,histentry)
9292 let histcnt = histcnt + 1
9293 continue
9294 endif
9295 let tgtdict[histentry] = histcnt
9296 let ehistentry = escape(histentry,g:netrw_menu_escape)
9297" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009298 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 +02009299 endif
9300 let histcnt = histcnt + 1
9301 endwhile
9302 endif
9303 endif
9304" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009305endfun
9306
9307" ---------------------------------------------------------------------
9308" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9309" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009310fun! s:NetrwTreeDir(islocal)
9311" 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 +02009312" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009313" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9314" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9315" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009316" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009318 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009319 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009320" 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 +01009321 let treedir= s:treedir
9322 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009323 unlet s:prevwinopen
9324" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009325 return treedir
9326 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009327 if exists("s:prevwinopen")
9328 unlet s:prevwinopen
9329 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009330" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009331
Bram Moolenaar8d043172014-01-23 14:24:41 +01009332 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9333 let b:netrw_curdir= getcwd()
9334 endif
9335 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009336" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009337" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009339 let s:treecurpos= winsaveview()
9340" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009341" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009342
9343 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009344" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9345" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009346" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009347
9348 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009349 let curline= substitute(getline('.'),"\t -->.*$",'','')
9350 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009351" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009352 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9354 elseif curline =~ '@$'
9355" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009356 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009357" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009358 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009360 let treedir= ""
9361 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009362" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009363
9364 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9366" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009367" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009368 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9372 sil! NetrwKeepj %d _
9373" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009374 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009375" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009376" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009377 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009378" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009379
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009380" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009381" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009382" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009383
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009384 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9385" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9386" let newdir = w:netrw_treetop.'/'.potentialdir
9387" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9388" let treedir = s:NetrwTreePath(newdir)
9389" let w:netrw_treetop = newdir
9390" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9391" else
9392" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009393 if a:islocal && curline =~ '@$'
9394 if isdirectory(s:NetrwFile(potentialdir))
9395 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9396 let w:netrw_treetop = treedir
9397 endif
9398 else
9399 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9400 let treedir = s:NetrwTreePath(w:netrw_treetop)
9401 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009402 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009403" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009404
9405 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009407" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009408" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009409
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009410" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009411 return treedir
9412endfun
9413
9414" ---------------------------------------------------------------------
9415" s:NetrwTreeDisplay: recursive tree display {{{2
9416fun! s:NetrwTreeDisplay(dir,depth)
9417" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9418
9419 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009420 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009421
9422 " install ../ and shortdir
9423 if a:depth == ""
9424 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009426 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009428 if a:dir == w:netrw_treetop
9429 let shortdir= a:dir
9430 else
9431 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9432 endif
9433 call setline(line("$")+1,a:depth.shortdir)
9434 else
9435 let shortdir= substitute(a:dir,'^.*/','','e')
9436 call setline(line("$")+1,a:depth.shortdir.'/')
9437 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009439 " append a / to dir if its missing one
9440 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009441
9442 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009443 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009445
Bram Moolenaar85850f32019-07-19 22:05:51 +02009446 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9447 if g:netrw_hide == 1
9448 " hide given patterns
9449 let listhide= split(g:netrw_list_hide,',')
9450" call Decho("listhide=".string(listhide))
9451 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009452 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009453 endfor
9454
9455 elseif g:netrw_hide == 2
9456 " show given patterns (only)
9457 let listhide= split(g:netrw_list_hide,',')
9458" call Decho("listhide=".string(listhide))
9459 let entries=[]
9460 for entry in w:netrw_treedict[dir]
9461 for pat in listhide
9462 if entry =~ pat
9463 call add(entries,entry)
9464 break
9465 endif
9466 endfor
9467 endfor
9468 let w:netrw_treedict[dir]= entries
9469 endif
9470 if depth != ""
9471 " always remove "." and ".." entries when there's depth
9472 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9473 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9474 endif
9475
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009476" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009477 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009478 if dir =~ '/$'
9479 let direntry= substitute(dir.entry,'[@/]$','','e')
9480 else
9481 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9482 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009483" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009485" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009486 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009487 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009488" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9489 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9490 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9491" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009492 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009493 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009494" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009495 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009496 endif
9497 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009498" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009499
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500" call Dret("NetrwTreeDisplay")
9501endfun
9502
9503" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009504" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9505fun! s:NetrwRefreshTreeDict(dir)
9506" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009507 if !exists("w:netrw_treedict")
9508" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9509 return
9510 endif
9511
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009512 for entry in w:netrw_treedict[a:dir]
9513 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9514" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9515
9516 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9517" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9518 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009519 let liststar = s:NetrwGlob(direntry,'*',1)
9520 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009521 let w:netrw_treedict[direntry] = liststar + listdotstar
9522" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9523
9524 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9525" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9526 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009527 let liststar = s:NetrwGlob(direntry.'/','*',1)
9528 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009529 let w:netrw_treedict[direntry]= liststar + listdotstar
9530" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9531
9532 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9533" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9534 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009535 let liststar = s:NetrwGlob(direntry.'/','*',1)
9536 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009537" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9538
9539 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009540" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009541 endif
9542 endfor
9543" call Dret("s:NetrwRefreshTreeDict")
9544endfun
9545
9546" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009547" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009548" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009549fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009550 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009551" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009552" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9553" 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>"))
9554" 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 +00009555
9556 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009557 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009558" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009559 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009560 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009561" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009562 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 +02009563" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009564 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009565 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009566" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009567 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009568 if exists("w:netrw_treetop")
9569 let s:netrw_treetop= w:netrw_treetop
9570 else
9571 let w:netrw_treetop= getcwd()
9572 let s:netrw_treetop= w:netrw_treetop
9573 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009574
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576 " insure that we have a treedict, albeit empty
9577" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 let w:netrw_treedict= {}
9579 endif
9580
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009581 " update the dictionary for the current directory
9582" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009583" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009584 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009586" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009587 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588
9589 " if past banner, record word
9590 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9591 let fname= expand("<cword>")
9592 else
9593 let fname= ""
9594 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009595" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9596" 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 +00009597
9598 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009599" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009600 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009601" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009602
9603 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9604 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009605" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009606 1d
9607 endwhile
9608
Bram Moolenaar13600302014-05-22 18:26:40 +02009609 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009610
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009611" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009612 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009613 endif
9614endfun
9615
9616" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009617" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009618" Normally, treetop is w:netrw_treetop, but a
9619" user of the function ( netrw#SetTreetop() )
9620" wipes that out prior to calling this function
9621fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009622" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9623 if line(".") < w:netrw_bannercnt + 2
9624 let treedir= a:treetop
9625 if treedir !~ '/$'
9626 let treedir= treedir.'/'
9627 endif
9628" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9629 return treedir
9630 endif
9631
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009632 let svpos = winsaveview()
9633" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009634 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009635" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009636 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009637" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9638 let curline= getline('.')
9639" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9640 if curline =~ '/$'
9641" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9642 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9643" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9644 elseif curline =~ '@\s\+-->'
9645" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9646 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9647 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9648" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009649 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009651 let treedir= ""
9652 endif
9653 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009654" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9655" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009656 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9657 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9658 let treedir= dirname.treedir
9659 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009661 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009662" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009663 if a:treetop =~ '/$'
9664 let treedir= a:treetop.treedir
9665 else
9666 let treedir= a:treetop.'/'.treedir
9667 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009668" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009669 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009670" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009671" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9672 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009673" call Dret("s:NetrwTreePath <".treedir.">")
9674 return treedir
9675endfun
9676
9677" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009678" s:NetrwWideListing: {{{2
9679fun! s:NetrwWideListing()
9680
9681 if w:netrw_liststyle == s:WIDELIST
9682" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9683 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009684 " cpf: characters per filename
9685 " fpl: filenames per line
9686 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009687 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009688 let dict={}
9689 " save the unnamed register and register 0-9 and a
9690 let dict.a=[getreg('a'), getregtype('a')]
9691 for i in range(0, 9)
9692 let dict[i] = [getreg(i), getregtype(i)]
9693 endfor
9694 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009696 let b:netrw_cpf= 0
9697 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009698 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009699 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9700 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009702 " restore stored registers
9703 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704" call Dret("NetrwWideListing")
9705 return
9706 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009707 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009708 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009709" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009710
9711 " determine qty files per line (fpl)
9712 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9713 if w:netrw_fpl <= 0
9714 let w:netrw_fpl= 1
9715 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009716" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717
9718 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009719 " fpc: files per column of wide listing
9720 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009721 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009722 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9723 let newcolstart = w:netrw_bannercnt + fpc
9724 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009725" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009726 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009727" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009728 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009729 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009730 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009731 while line("$") >= newcolstart
9732 if newcolend > line("$") | let newcolend= line("$") | endif
9733 let newcolqty= newcolend - newcolstart
9734 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009735 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009736 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009737 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009739 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009741 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009742 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009743 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009744 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009745" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009746 if @* != keepregstar | sil! let @* = keepregstar | endif
9747 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009748 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009749 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9750 NetrwKeepj call histdel("/",-1)
9751 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9752 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009753" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009754 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009755 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009756" 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 +00009757" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009758 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009759 else
9760 if hasmapto("w","n")
9761 sil! nunmap <buffer> w
9762 endif
9763 if hasmapto("b","n")
9764 sil! nunmap <buffer> b
9765 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009767endfun
9768
9769" ---------------------------------------------------------------------
9770" s:PerformListing: {{{2
9771fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009772" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9773" 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 +02009774" 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>"))
9775 sil! NetrwKeepj %d _
9776" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009777
Bram Moolenaar15146672011-10-20 22:22:38 +02009778 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009779" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009780 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009781
Bram Moolenaar85850f32019-07-19 22:05:51 +02009782 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009783 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009784" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009785
9786" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009787" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009788" endif " Decho
9789
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009790" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009791 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9792 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9794 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 endif
9796
9797 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009798 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009799
9800 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009801 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009802" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009803 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009804 if exists("g:netrw_pchk")
9805 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9806 " failure detections.
9807 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009808 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009809 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9810 endif
9811 if exists("g:netrw_pchk")
9812 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9813 else
9814 let curdir= b:netrw_curdir
9815 endif
9816 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9817 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9818 else
9819 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009820 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009821 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009822 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009823 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009825 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009826 let w:netrw_bannercnt= 1
9827 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009828" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9829" 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 +00009830
Bram Moolenaar85850f32019-07-19 22:05:51 +02009831 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009833 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 let sortby= sortby." reversed"
9835 endif
9836
9837 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009838 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009839" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009840 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009841" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009842 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009843 NetrwKeepj put ='\" Sorted by '.sortby
9844 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009845 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9846 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009847" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009848 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009849 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009850 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9851 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009852 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009853" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" 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 +00009855 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856
Bram Moolenaar85850f32019-07-19 22:05:51 +02009857 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009858 if g:netrw_banner
9859 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009861 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009862 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009863 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009864 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009865 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009866 endif
9867 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009871 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009872 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873
9874 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009875 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009876" 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 +01009877 if g:netrw_list_hide != "" && g:netrw_hide
9878 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009879 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009880 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009881 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009882 endif
9883 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009885 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009886
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" 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 +01009888 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009889" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009890 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009891" 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 +01009892 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009893 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009894" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" 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 +00009896 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897
9898 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009899 if g:netrw_banner
9900 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009901 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" 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 +01009903" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" 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 +01009905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906
Bram Moolenaar446cb832008-06-24 21:56:24 +00009907 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009911 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009912 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009913 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009914" 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 +01009915" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9916 return
9917 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919
9920 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009921 if !exists("w:netrw_bannercnt")
9922 let w:netrw_bannercnt= 0
9923 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9925" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9926" 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 +01009927
Bram Moolenaar5c736222010-01-06 20:54:52 +01009928 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009929" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" 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 +00009931 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009932 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009934 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009937 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009939" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941
Bram Moolenaar5c736222010-01-06 20:54:52 +01009942 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009944 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009945 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947 else
9948 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009949 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950 endif
9951 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009952
Bram Moolenaar446cb832008-06-24 21:56:24 +00009953 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9956 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009957
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009958 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009959 " exten: sort by extension
9960 " The histdel(...,-1) calls remove the last search from the search history
9961" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009962 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9963 NetrwKeepj call histdel("/",-1)
9964 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9965 NetrwKeepj call histdel("/",-1)
9966 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9967 NetrwKeepj call histdel("/",-1)
9968 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9969" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009970 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009971 " normal direction sorting
9972 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9973 else
9974 " reverse direction sorting
9975 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9976 endif
9977 endif
9978 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9979 NetrwKeepj call histdel("/",-1)
9980
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009982 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009984 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009991" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9993 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009994 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 endif
9996
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009997 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009999 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010000 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010001 call histdel("/",-1)
10002 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 endif
10004 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010005" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006
10007 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10009" 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 +010010010 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" 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 +010010012 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" 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 +000010014
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010015 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010016 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010017" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010018 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 endif
10020
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010022 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10024 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010025 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10027 else
10028" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10029" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10030" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10031" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 endif
10033
10034 " record previous current directory
10035 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010036" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037
10038 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10040" 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 +010010041 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010042" 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 +020010043 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010044" 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 +000010045
10046 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010048 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010049" 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 +010010050 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010051" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010052 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10053 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010054" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010055" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056
Bram Moolenaar8d043172014-01-23 14:24:41 +010010057 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010058" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10059" 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 +010010060" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10061 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010062 unlet s:treecurpos
10063 endif
10064
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065" 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>"))
10066" 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 +000010067" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10068endfun
10069
10070" ---------------------------------------------------------------------
10071" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010072fun! s:SetupNetrwStatusLine(statline)
10073" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10074
10075 if !exists("s:netrw_setup_statline")
10076 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010078
10079 if !exists("s:netrw_users_stl")
10080 let s:netrw_users_stl= &stl
10081 endif
10082 if !exists("s:netrw_users_ls")
10083 let s:netrw_users_ls= &laststatus
10084 endif
10085
10086 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010087 let dict={}
10088 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010089 redir @a
10090 try
10091 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010093 if &bg == "dark"
10094 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10095 else
10096 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10097 endif
10098 endtry
10099 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010100 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010101 endif
10102
10103 " set up status line (may use User9 highlighting)
10104 " insure that windows have a statusline
10105 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010106 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010107 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010109 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010110
10111" call Dret("SetupNetrwStatusLine : stl=".&stl)
10112endfun
10113
Bram Moolenaar85850f32019-07-19 22:05:51 +020010114" =========================================
10115" Remote Directory Browsing Support: {{{1
10116" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010117
10118" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010119" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10120" This function assumes that a long listing will be received. Size, time,
10121" and reverse sorts will be requested of the server but not otherwise
10122" enforced here.
10123fun! s:NetrwRemoteFtpCmd(path,listcmd)
10124" 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 +010010125" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010126 " sanity check: {{{3
10127 if !exists("w:netrw_method")
10128 if exists("b:netrw_method")
10129 let w:netrw_method= b:netrw_method
10130 else
10131 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10132" call Dret("NetrwRemoteFtpCmd")
10133 return
10134 endif
10135 endif
10136
10137 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10138 let ffkeep= &ff
10139 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010141
10142 " clear off any older non-banner lines " {{{3
10143 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010144" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10145 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010146
10147 ".........................................
10148 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10149 " ftp + <.netrc>: Method #2
10150 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010151 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010152 endif
10153 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010154 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010155" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010156 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010157 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010159 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" 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>"))
10161 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 +010010162 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10164 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 +010010165 endif
10166
10167 ".........................................
10168 elseif w:netrw_method == 3 " {{{3
10169 " ftp + machine,id,passwd,filename: Method #3
10170 setl ff=unix
10171 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010172 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010173 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010174 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010175 endif
10176
10177 " handle userid and password
10178 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010179" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010180 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10181 call NetUserPass("ftp:".host)
10182 endif
10183 if exists("g:netrw_uid") && g:netrw_uid != ""
10184 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010185 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010186 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010187 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010188 endif
10189 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010190 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010191 endif
10192 endif
10193
10194 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010195 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010196 endif
10197 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010198 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010199" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010200 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010201 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010202
10203 " perform ftp:
10204 " -i : turns off interactive prompting from ftp
10205 " -n unix : DON'T use <.netrc>, even though it exists
10206 " -n win32: quit being obnoxious about password
10207 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010208" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010209 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010210" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010211" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10212" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010213 endif
10214
10215 ".........................................
10216 elseif w:netrw_method == 9 " {{{3
10217 " sftp username@machine: Method #9
10218 " s:netrw_sftp_cmd
10219 setl ff=unix
10220
10221 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010222 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010223" call Dret("NetrwRemoteFtpCmd")
10224 return
10225
10226 ".........................................
10227 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010228 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010229 endif
10230
10231 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010232 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010233 sil! NetrwKeepj %s/\r$//e
10234 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010235 endif
10236 if a:listcmd == "dir"
10237 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010238 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10239 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10240 NetrwKeepj call histdel("/",-1)
10241 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010242 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 +010010243 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10244 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010245 endif
10246 endif
10247
10248 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10249 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010250 exe 'NetrwKeepj '.w:netrw_bannercnt
10251 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010252 endif
10253 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010254 exe 'NetrwKeepj '.w:netrw_bannercnt
10255 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010256 endif
10257
10258 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010259 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010260" call Dret("NetrwRemoteFtpCmd")
10261endfun
10262
10263" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010264" s:NetrwRemoteListing: {{{2
10265fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010266" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010267
Bram Moolenaara6878372014-03-22 21:02:50 +010010268 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10269 let w:netrw_bannercnt= s:bannercnt
10270 endif
10271 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010272 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 endif
10274
Bram Moolenaar446cb832008-06-24 21:56:24 +000010275 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010276
Bram Moolenaar446cb832008-06-24 21:56:24 +000010277 " sanity check:
10278 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010279" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010280 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010281" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010282 if !exists("g:netrw_quiet")
10283 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10284 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010285 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010286" call Dret("s:NetrwRemoteListing -1")
10287 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010288 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010289
Bram Moolenaar8d043172014-01-23 14:24:41 +010010290 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010291" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010292 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010293 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294 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 +000010295 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010296 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 +000010297 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010298 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010299
Bram Moolenaar85850f32019-07-19 22:05:51 +020010300 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010301" call Dret("s:NetrwRemoteListing -1")
10302 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010303 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010304" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010305
Bram Moolenaar446cb832008-06-24 21:56:24 +000010306 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010307" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010308 let w:netrw_method= b:netrw_method
10309 endif
10310
Bram Moolenaar13600302014-05-22 18:26:40 +020010311 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010312 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010313" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010314 let s:method = "ftp"
10315 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010316 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010317 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010318 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010319 let listcmd= g:netrw_ftp_sizelist_cmd
10320 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010321" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010322 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010323" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010324
Bram Moolenaara6878372014-03-22 21:02:50 +010010325 " report on missing file or directory messages
10326 if search('[Nn]o such file or directory\|Failed to change directory')
10327 let mesg= getline(".")
10328 if exists("w:netrw_bannercnt")
10329 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010330 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010331 setl noma
10332 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010333 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010334 call netrw#ErrorMsg(s:WARNING,mesg,96)
10335" call Dret("s:NetrwRemoteListing : -1")
10336 return -1
10337 endif
10338
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010339 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 +000010340 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010341" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010342 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010343
10344 " cleanup
10345 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010346 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10347 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010348 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010349 sil! NetrwKeepj %s/\r$//e
10350 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010351
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010352 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010353 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010354 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010355 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010356" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010358" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010359 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010360 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010361 exe "sil! NetrwKeepj ".line1
10362 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010363
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010364" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010366" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010367 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10368 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010370" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010371 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10372 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10373 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10374 NetrwKeepj call histdel("/",-1)
10375 NetrwKeepj call histdel("/",-1)
10376 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 endif
10378 endif
10379
Bram Moolenaar13600302014-05-22 18:26:40 +020010380 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010384" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010386" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10387 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010389 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10390 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10391 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10392 NetrwKeepj call histdel("/",-1)
10393 NetrwKeepj call histdel("/",-1)
10394 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010396 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10397 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 endif
10399 else
10400 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010402 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010403 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010404" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10405 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10406" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010407 endif
10408 endif
10409
10410 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010411 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010413 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10414 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 endif
10416 endif
10417
10418 if w:netrw_liststyle == s:LONGLIST
10419 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010420" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421
10422 if s:method == "ftp"
10423 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010424 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010425 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010426 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010428 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010430 sil! NetrwKeepj 1
10431 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432 let line2= line(".")
10433 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010435 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436 endif
10437 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010438 exe "sil! NetrwKeepj ".line1
10439 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440 endif
10441
10442 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010444 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 +000010445 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010447 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010449 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10450 NetrwKeepj call histdel("/",-1)
10451 NetrwKeepj call histdel("/",-1)
10452 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453 endif
10454 endif
10455
10456" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010459
10460" call Dret("s:NetrwRemoteListing 0")
10461 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010462endfun
10463
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464" ---------------------------------------------------------------------
10465" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10466fun! s:NetrwRemoteRm(usrhost,path) range
10467" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010469 let svpos= winsaveview()
10470" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471
10472 let all= 0
10473 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10474 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 for fname in s:netrwmarkfilelist_{bufnr("%")}
10477 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010478 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010480 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 let all= 1
10482 endif
10483 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010484 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485
10486 else
10487 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489
10490 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010491 let keepsol = &l:sol
10492 setl nosol
10493 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494
10495 " remove multiple files and directories
10496 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010497 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010499 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010500 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010501 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 let all= 1
10503 endif
10504 let ctr= ctr + 1
10505 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 endif
10508
10509 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010510" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010511 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010512" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10513 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514
10515" call Dret("s:NetrwRemoteRm")
10516endfun
10517
10518" ---------------------------------------------------------------------
10519" s:NetrwRemoteRmFile: {{{2
10520fun! s:NetrwRemoteRmFile(path,rmfile,all)
10521" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10522
10523 let all= a:all
10524 let ok = ""
10525
10526 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10527 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010528" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 if !all
10530 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010531" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010532 call inputsave()
10533 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10534 call inputrestore()
10535 echohl NONE
10536 if ok == ""
10537 let ok="no"
10538 endif
10539 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010540 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 let all= 1
10542 endif
10543 endif
10544
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010545 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010546" 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 +000010547 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010548" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010550 if path =~ '^\a\{3,}://'
10551 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010553 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10555 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010558" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010560 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 let ok="q"
10562 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010563 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010564" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10565" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10566" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010568 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010570 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010572" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010574 if v:shell_error != 0
10575 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010576 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 +010010577 else
10578 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10579 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010580 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010581 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010583" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 endif
10585 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010586 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010587" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588 endif
10589
10590 else
10591 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 if !all
10594 call inputsave()
10595 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10596 call inputrestore()
10597 if ok == ""
10598 let ok="no"
10599 endif
10600 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010601 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 let all= 1
10603 endif
10604 endif
10605
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010606 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010608 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609 else
10610 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010611 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10612" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010613 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615
10616 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010617" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10618 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10619" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010620 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010621" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622
10623 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010624 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010625 endif
10626 endif
10627 endif
10628
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010629 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631 endif
10632 endif
10633
10634" call Dret("s:NetrwRemoteRmFile ".ok)
10635 return ok
10636endfun
10637
10638" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639" s:NetrwRemoteRename: rename a remote file or directory {{{2
10640fun! s:NetrwRemoteRename(usrhost,path) range
10641" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10642
10643 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010644 let svpos = winsaveview()
10645" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 let ctr = a:firstline
10647 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10648
10649 " rename files given by the markfilelist
10650 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10651 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 if exists("subfrom")
10654 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010656 else
10657 call inputsave()
10658 let newname= input("Moving ".oldname." to : ",oldname)
10659 call inputrestore()
10660 if newname =~ '^s/'
10661 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10662 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10663 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 endif
10666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010669 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010670 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671 let oldname= s:ShellEscape(a:path.oldname)
10672 let newname= s:ShellEscape(a:path.newname)
10673" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010674 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 endif
10676
10677 endfor
10678 call s:NetrwUnMarkFile(1)
10679
10680 else
10681
10682 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683 let keepsol= &l:sol
10684 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010685 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010686 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687
10688 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010690
10691 call inputsave()
10692 let newname= input("Moving ".oldname." to : ",oldname)
10693 call inputrestore()
10694
10695 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10696 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10697 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698 let oldname= s:ShellEscape(a:path.oldname)
10699 let newname= s:ShellEscape(a:path.newname)
10700" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010701 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702 endif
10703
10704 let ctr= ctr + 1
10705 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010706 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010707 endif
10708
10709 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010710 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010711" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10712 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713
10714" call Dret("NetrwRemoteRename")
10715endfun
10716
Bram Moolenaar85850f32019-07-19 22:05:51 +020010717" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010718" Local Directory Browsing Support: {{{1
10719" ==========================================
10720
10721" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010722" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010723" Should accept: file://localhost/etc/fstab
10724" file:///etc/fstab
10725" file:///c:/WINDOWS/clock.avi
10726" file:///c|/WINDOWS/clock.avi
10727" file://localhost/c:/WINDOWS/clock.avi
10728" file://localhost/c|/WINDOWS/clock.avi
10729" file://c:/foo.txt
10730" file:///c:/foo.txt
10731" 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 +020010732fun! netrw#FileUrlEdit(fname)
10733" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010734 let fname = a:fname
10735 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010736" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010737 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010738" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010739 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010740 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010741 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010742" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010743 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010744" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010745 endif
10746 endif
10747 let fname2396 = netrw#RFC2396(fname)
10748 let fname2396e= fnameescape(fname2396)
10749 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010750 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010752 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010753" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010754 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10755 endif
10756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010757
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10759" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010760 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010761 exe 'NetrwKeepj keepalt edit '.plainfname
10762 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10763
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010764" 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 +020010765" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010766 exe "sil doau BufReadPost ".fname2396e
10767endfun
10768
10769" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770" netrw#LocalBrowseCheck: {{{2
10771fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010772 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010773 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10774 "
10775 " unfortunate interaction -- split window debugging can't be used here, must use
10776 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10777 " another call to LocalBrowseCheck() when attempts to write
10778 " to the DBG buffer are made.
10779 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010780 " The &ft == "netrw" test was installed because the BufEnter event
10781 " would hit when re-entering netrw windows, creating unexpected
10782 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010783" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010784" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010785" 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 +010010786 " getting E930: Cannot use :redir inside execute
10787"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010788" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10789" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010790
Bram Moolenaar97d62492012-11-15 21:28:22 +010010791 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792 if isdirectory(s:NetrwFile(a:dirname))
10793" 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 +010010794
Bram Moolenaar97d62492012-11-15 21:28:22 +010010795 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010796" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10797" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010798 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010799
Bram Moolenaar446cb832008-06-24 21:56:24 +000010800 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010801" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010802 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010803
Bram Moolenaar5c736222010-01-06 20:54:52 +010010804 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010805" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010806 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010807 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010808 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010809" 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 +010010810" call Dret("netrw#LocalBrowseCheck")
10811 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010813
Bram Moolenaar85850f32019-07-19 22:05:51 +020010814 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010815 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10816 " AND IF the listing style is not a tree listing
10817 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010818" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010819 let ibuf = 1
10820 let buflast = bufnr("$")
10821 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010822 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10823 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010824 endif
10825 let ibuf= ibuf + 1
10826 endwhile
10827 endif
10828 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" 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>"))
10830" 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 +000010831 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010832" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010833endfun
10834
10835" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010836" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010837" performed any shell command. The idea is to cause all local-browsing
10838" buffers to be refreshed after a user has executed some shell command,
10839" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010840fun! s:LocalBrowseRefresh()
10841" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10843" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010844
Bram Moolenaar446cb832008-06-24 21:56:24 +000010845 " determine which buffers currently reside in a tab
10846 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010847" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010848 return
10849 endif
10850 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010851" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010852 return
10853 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010854 if !empty(getcmdwintype())
10855 " cannot move away from cmdline window, see :h E11
10856 return
10857 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010858 if exists("s:netrw_events") && s:netrw_events == 1
10859 " s:LocalFastBrowser gets called (indirectly) from a
10860 let s:netrw_events= 2
10861" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10862 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010863 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010864 let itab = 1
10865 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010866 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010867 while itab <= tabpagenr("$")
10868 let buftablist = buftablist + tabpagebuflist()
10869 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010870 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010871 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10873" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10875 " | refresh any netrw window
10876 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878 let ibl = 0
10879 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010880" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010881 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10882 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010883 " (ibuf not shown in a current window AND
10884 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10886 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010887 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010888" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010889 continue
10890 elseif index(tabpagebuflist(),ibuf) != -1
10891 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010893 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010894 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010895 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10896 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10897 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010900 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10901 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10902 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010903 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010904 endif
10905 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010907 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010908" call Decho("restore window: win_gotoid(".curwinid.")")
10909 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010910 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010911
Bram Moolenaara6878372014-03-22 21:02:50 +010010912" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010913endfun
10914
10915" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010916" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10917"
10918" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010919" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010920" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10921" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010922" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923"
10924" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10925" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010926" (re-using a buffer may not be as accurate)
10927"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010928" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010929" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10930" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10931" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10932" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010933fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010934" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10935" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10936" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10937" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010938
10939 " initialize browselist, a list of buffer numbers that the local browser has used
10940 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010941" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010942 let s:netrw_browselist= []
10943 endif
10944
10945 " append current buffer to fastbrowse list
10946 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010947" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010948 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010949" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010950 endif
10951
10952 " enable autocmd events to handle refreshing/removing local browser buffers
10953 " If local browse buffer is currently showing: refresh it
10954 " If local browse buffer is currently hidden : wipe it
10955 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10956 " =1 : medium speed, re-use directory listing for remote only
10957 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010958 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10959 let s:netrw_events= 1
10960 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010961 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010962 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010964 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010965 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010967 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010968 endif
10969 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010970
10971 " user must have changed fastbrowse to its fast setting, so remove
10972 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010973 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010975 unlet s:netrw_events
10976 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010977 au!
10978 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010979 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010980 endif
10981
Bram Moolenaar85850f32019-07-19 22:05:51 +020010982" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010983endfun
10984
10985" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010986" s:LocalListing: does the job of "ls" for local directories {{{2
10987fun! s:LocalListing()
10988" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10990" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10991" 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 +010010992
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" 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
10994" 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
10995" 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 +010010996
10997 " get the list of files contained in the current directory
10998 let dirname = b:netrw_curdir
10999 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011000 let filelist = s:NetrwGlob(dirname,"*",0)
11001 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011002" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011003
Nir Lichtman1e34b952024-05-08 19:19:34 +020011004 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011006 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11007 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011009 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011011 endif
11012
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011013" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011014" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011015" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011016
11017 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11018 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11019 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011020" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11021" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011022 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" 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 +010011024
11025 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011026" call Decho(" ",'~'.expand("<slnum>"))
11027" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011028
11029 if getftype(filename) == "link"
11030 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011032 let pfile= filename."@"
11033
11034 elseif getftype(filename) == "socket"
11035 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011036" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011037 let pfile= filename."="
11038
11039 elseif getftype(filename) == "fifo"
11040 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011042 let pfile= filename."|"
11043
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011044 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011045 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011046" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011047 let pfile= filename."/"
11048
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011050 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11052 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011053" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011054 let pfile= filename."*"
11055 else
11056 " normal file
11057 let pfile= filename
11058 endif
11059 elseif executable(filename)
11060 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011061" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011062 let pfile= filename."*"
11063 else
11064 " normal file
11065 let pfile= filename
11066 endif
11067
11068 else
11069 " normal file
11070 let pfile= filename
11071 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011073
11074 if pfile =~ '//$'
11075 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011076" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011077 endif
11078 let pfile= strpart(pfile,dirnamelen)
11079 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11081" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011082
11083 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011084 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11085 let sz = getfsize(filename)
11086 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11087 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011088
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011089 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011090 let sz= s:NetrwHumanReadable(sz)
11091 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011092 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011093 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011094" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011095 endif
11096
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011097 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011098 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011099 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011100" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011102 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011103 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011104" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011106 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011107
11108 elseif g:netrw_sort_by =~ "^s"
11109 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011110" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011112 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011113 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011116 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011117
11118 else
11119 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011120" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011122 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011124" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011125 endfor
11126
11127 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011128 sil! NetrwKeepj g/^$/d
11129 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11133
11134" call Dret("s:LocalListing")
11135endfun
11136
11137" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011138" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11139fun! s:NetrwLocalExecute(cmd)
11140" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11141 let ykeep= @@
11142 " sanity check
11143 if !executable(a:cmd)
11144 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11145 let @@= ykeep
11146" call Dret("s:NetrwLocalExecute")
11147 return
11148 endif
11149
11150 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011152 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011154
11155 " strip any ansi escape sequences off
11156 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11157
11158 " show user the result(s)
11159 echomsg result
11160 let @@= ykeep
11161
11162" call Dret("s:NetrwLocalExecute")
11163endfun
11164
11165" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011166" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011167fun! s:NetrwLocalRename(path) range
11168" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11169
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011170 if !exists("w:netrw_bannercnt")
11171 let w:netrw_bannercnt= b:netrw_bannercnt
11172 endif
11173
Bram Moolenaar97d62492012-11-15 21:28:22 +010011174 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011175 let ykeep = @@
11176 let ctr = a:firstline
11177 let svpos = winsaveview()
11178 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011179" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011180
11181 " rename files given by the markfilelist
11182 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11183 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011184" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011185 if exists("subfrom")
11186 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011187" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011188 else
11189 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011190 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011191 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011192 if newname =~ ''
11193 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11194 let newname = substitute(newname,'^.*','','')
11195 elseif newname =~ ''
11196 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11197 let newname = substitute(newname,'[^/]*','','')
11198 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011199 if newname =~ '^s/'
11200 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11201 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011202" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011203 let newname = substitute(oldname,subfrom,subto,'')
11204 endif
11205 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011206 if !all && filereadable(newname)
11207 call inputsave()
11208 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11209 call inputrestore()
11210 if response == "all"
11211 let all= 1
11212 elseif response != "y" && response != "yes"
11213 " refresh the directory
11214" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11215 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11216" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11217 NetrwKeepj call winrestview(svpos)
11218 let @@= ykeep
11219" call Dret("NetrwLocalRename")
11220 return
11221 endif
11222 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011223 call rename(oldname,newname)
11224 endfor
11225 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011226
Bram Moolenaar97d62492012-11-15 21:28:22 +010011227 else
11228
11229 " attempt to rename files/directories
11230 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011231 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011232
11233 " sanity checks
11234 if line(".") < w:netrw_bannercnt
11235 let ctr= ctr + 1
11236 continue
11237 endif
11238 let curword= s:NetrwGetWord()
11239 if curword == "./" || curword == "../"
11240 let ctr= ctr + 1
11241 continue
11242 endif
11243
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011244 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011246" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011247
11248 call inputsave()
11249 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11250 call inputrestore()
11251
11252 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011253" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011254
11255 let ctr= ctr + 1
11256 endwhile
11257 endif
11258
11259 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011260" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011261 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011262" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11263 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011264 let @@= ykeep
11265
11266" call Dret("NetrwLocalRename")
11267endfun
11268
11269" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011270" s:NetrwLocalRm: {{{2
11271fun! s:NetrwLocalRm(path) range
11272" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011273" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011274
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011275 if !exists("w:netrw_bannercnt")
11276 let w:netrw_bannercnt= b:netrw_bannercnt
11277 endif
11278
Bram Moolenaar446cb832008-06-24 21:56:24 +000011279 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011280 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011281 let ret = 0
11282 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011283 let svpos = winsaveview()
11284" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011285
11286 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11287 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011288" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011289 for fname in s:netrwmarkfilelist_{bufnr("%")}
11290 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011291 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011292 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011293 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011294 let all= 1
11295 endif
11296 endfor
11297 call s:NetrwUnMarkFile(1)
11298
11299 else
11300 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011301" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011302
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011303 let keepsol= &l:sol
11304 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011305 let ctr = a:firstline
11306 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011307 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011308
11309 " sanity checks
11310 if line(".") < w:netrw_bannercnt
11311 let ctr= ctr + 1
11312 continue
11313 endif
11314 let curword= s:NetrwGetWord()
11315 if curword == "./" || curword == "../"
11316 let ctr= ctr + 1
11317 continue
11318 endif
11319 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011320 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011321 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011322 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011323 let all= 1
11324 endif
11325 let ctr= ctr + 1
11326 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011327 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011328 endif
11329
11330 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011331" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011332 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011333 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011334" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11335 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011336 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011337 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011338
11339" call Dret("s:NetrwLocalRm")
11340endfun
11341
11342" ---------------------------------------------------------------------
11343" s:NetrwLocalRmFile: remove file fname given the path {{{2
11344" Give confirmation prompt unless all==1
11345fun! s:NetrwLocalRmFile(path,fname,all)
11346" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011347
Bram Moolenaar446cb832008-06-24 21:56:24 +000011348 let all= a:all
11349 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011350 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011351 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011352" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011353
11354 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11355 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011356" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011357 if !all
11358 echohl Statement
11359 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011360 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361 call inputrestore()
11362 echohl NONE
11363 if ok == ""
11364 let ok="no"
11365 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011366" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011368" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011369 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370 let all= 1
11371 endif
11372 endif
11373
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011374 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011375 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011376" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011377 endif
11378
11379 else
11380 " attempt to remove directory
11381 if !all
11382 echohl Statement
11383 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011384 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 call inputrestore()
11386 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11387 if ok == ""
11388 let ok="no"
11389 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011390 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011391 let all= 1
11392 endif
11393 endif
11394 let rmfile= substitute(rmfile,'[\/]$','','e')
11395
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011396 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011397 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011398 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 endif
11400 endif
11401 endif
11402
11403" call Dret("s:NetrwLocalRmFile ".ok)
11404 return ok
11405endfun
11406
Bram Moolenaar85850f32019-07-19 22:05:51 +020011407" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011408" Support Functions: {{{1
11409
Bram Moolenaar488c6512005-08-11 20:09:58 +000011410" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011411" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11412" 0: marked file list of current buffer
11413" 1: marked file target
11414fun! netrw#Access(ilist)
11415 if a:ilist == 0
11416 if exists("s:netrwmarkfilelist_".bufnr('%'))
11417 return s:netrwmarkfilelist_{bufnr('%')}
11418 else
11419 return "no-list-buf#".bufnr('%')
11420 endif
11421 elseif a:ilist == 1
11422 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011423 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011424endfun
11425
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011426" ---------------------------------------------------------------------
11427" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11428fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011429 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011430endfun
11431
Bram Moolenaara6878372014-03-22 21:02:50 +010011432" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011433" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11434" I expect this function to be used in
11435" :PChkAssert netrw#Expose("netrwmarkfilelist")
11436" for example.
11437fun! netrw#Expose(varname)
11438" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011439 if exists("s:".a:varname)
11440 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011441" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011442 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011443" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011444 if type(retval) == 3
11445 let retval = copy(retval)
11446 let i = 0
11447 while i < len(retval)
11448 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11449 let i = i + 1
11450 endwhile
11451 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011452" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011453 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011454 else
11455" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011456 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011457 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011458" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011459 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011460 endif
11461
11462" call Dret("netrw#Expose ".string(retval))
11463 return retval
11464endfun
11465
11466" ---------------------------------------------------------------------
11467" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11468fun! netrw#Modify(varname,newvalue)
11469" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11470 exe "let s:".a:varname."= ".string(a:newvalue)
11471" call Dret("netrw#Modify")
11472endfun
11473
11474" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011475" netrw#RFC2396: converts %xx into characters {{{2
11476fun! netrw#RFC2396(fname)
11477" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011478 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011479" call Dret("netrw#RFC2396 ".fname)
11480 return fname
11481endfun
11482
11483" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011484" netrw#UserMaps: supports user-specified maps {{{2
11485" see :help function()
11486"
11487" g:Netrw_UserMaps is a List with members such as:
11488" [[keymap sequence, function reference],...]
11489"
11490" The referenced function may return a string,
11491" refresh : refresh the display
11492" -other- : this string will be executed
11493" or it may return a List of strings.
11494"
11495" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011496" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011497" Related functions:
11498" netrw#Expose(varname) -- see s:varname variables
11499" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11500" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11501fun! netrw#UserMaps(islocal)
11502" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11503" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11504
11505 " set up usermaplist
11506 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11507" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11508 for umap in g:Netrw_UserMaps
11509" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11510" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11511 " if umap[0] is a string and umap[1] is a string holding a function name
11512 if type(umap[0]) == 1 && type(umap[1]) == 1
11513" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11514 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11515 else
11516 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11517 endif
11518 endfor
11519 endif
11520" call Dret("netrw#UserMaps")
11521endfun
11522
11523" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011524" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11525fun! netrw#WinPath(path)
11526" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011527 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011528 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011529 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011530 " remove trailing slash (Win95)
11531 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11532 " remove escaped spaces
11533 let path = substitute(path, '\ ', ' ', 'g')
11534 " convert slashes to backslashes
11535 let path = substitute(path, '/', '\', 'g')
11536 else
11537 let path= a:path
11538 endif
11539" call Dret("netrw#WinPath <".path.">")
11540 return path
11541endfun
11542
11543" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011544" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11545fun! s:StripTrailingSlash(path)
11546 " remove trailing slash
11547 return substitute(a:path, '[/\\]$', '', 'g')
11548endfun
11549
Travis Sheltone34d0e32024-07-30 21:08:56 +020011550" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011551" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11552" cb : bl2mf=0 add marked files to buffer list
11553" cB : bl2mf=1 use bufferlist to mark files
11554" (mnemonic: cb = copy (marked files) to buffer list)
11555fun! s:NetrwBadd(islocal,bl2mf)
11556" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11557 if a:bl2mf
11558 " cB: add buffer list to marked files
11559 redir => bufl
11560 ls
11561 redir END
11562 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11563 for fname in bufl
11564 call s:NetrwMarkFile(a:islocal,fname)
11565 endfor
11566 else
11567 " cb: add marked files to buffer list
11568 for fname in s:netrwmarkfilelist_{bufnr("%")}
11569" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11570 exe "badd ".fnameescape(fname)
11571 endfor
11572 let curbufnr = bufnr("%")
11573 let curdir = s:NetrwGetCurdir(a:islocal)
11574 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11575 endif
11576" call Dret("s:NetrwBadd")
11577endfun
11578
11579" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011580" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11581fun! s:ComposePath(base,subdir)
11582" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11583
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011584 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011585" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011586 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011587 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011588 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011589 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011590 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011591 endif
11592
Bram Moolenaar85850f32019-07-19 22:05:51 +020011593 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011594 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011595" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011596 let ret= a:subdir
11597
Nir Lichtman1e34b952024-05-08 19:19:34 +020011598 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011599" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011600 if a:base =~ '[/\\]$'
11601 let ret= a:base.a:subdir
11602 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011603 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011604 endif
11605
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011606 elseif a:base =~ '^\a\{3,}://'
11607" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011608 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11609 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11610 if a:subdir == '../'
11611 if curpath =~ '[^/]/[^/]\+/$'
11612 let curpath= substitute(curpath,'[^/]\+/$','','')
11613 else
11614 let curpath=""
11615 endif
11616 let ret= urlbase.curpath
11617 else
11618 let ret= urlbase.curpath.a:subdir
11619 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011620" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11621" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11622" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011623
11624 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011625" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011626 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11627 if a:base =~ '^//'
11628 " keeping initial '//' for the benefit of network share listing support
11629 let ret= '/'.ret
11630 endif
11631 let ret= simplify(ret)
11632 endif
11633
11634" call Dret("s:ComposePath ".ret)
11635 return ret
11636endfun
11637
11638" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011639" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11640" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11641fun! s:DeleteBookmark(fname)
11642" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11643 call s:MergeBookmarks()
11644
11645 if exists("g:netrw_bookmarklist")
11646 let indx= index(g:netrw_bookmarklist,a:fname)
11647 if indx == -1
11648 let indx= 0
11649 while indx < len(g:netrw_bookmarklist)
11650 if g:netrw_bookmarklist[indx] =~ a:fname
11651 call remove(g:netrw_bookmarklist,indx)
11652 let indx= indx - 1
11653 endif
11654 let indx= indx + 1
11655 endwhile
11656 else
11657 " remove exact match
11658 call remove(g:netrw_bookmarklist,indx)
11659 endif
11660 endif
11661
11662" call Dret("s:DeleteBookmark")
11663endfun
11664
11665" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011666" s:FileReadable: o/s independent filereadable {{{2
11667fun! s:FileReadable(fname)
11668" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11669
11670 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011671 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011672 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011673 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011674 endif
11675
11676" call Dret("s:FileReadable ".ret)
11677 return ret
11678endfun
11679
11680" ---------------------------------------------------------------------
11681" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11682" Places correct suffix on end of temporary filename,
11683" using the suffix provided with fname
11684fun! s:GetTempfile(fname)
11685" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11686
11687 if !exists("b:netrw_tmpfile")
11688 " get a brand new temporary filename
11689 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011690" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011691
Bram Moolenaarc236c162008-07-13 17:41:49 +000011692 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011694
Bram Moolenaar9964e462007-05-05 17:54:07 +000011695 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011696 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11697" 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 +010011698 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011699" call Dret("s:GetTempfile getcwd<".getcwd().">")
11700 return ""
11701 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011702
Bram Moolenaar9964e462007-05-05 17:54:07 +000011703 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011704 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011705" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011706
Bram Moolenaar9964e462007-05-05 17:54:07 +000011707 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011708 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011709 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011710 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011711 if !exists("+shellslash") || !&ssl
11712 let tmpfile = substitute(tmpfile,'/','\','g')
11713 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011714 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011715 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011716 endif
11717 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011719 else
11720 " re-use temporary filename
11721 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011722" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011723 endif
11724
11725 " use fname's suffix for the temporary file
11726 if a:fname != ""
11727 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011728" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011729 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011730 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011731 elseif a:fname =~ '.txz$'
11732 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011733 else
11734 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11735 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011736" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011737 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011738" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011739 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011740" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011741 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11742 endif
11743 endif
11744
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011745" 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 +000011746" call Dret("s:GetTempfile <".tmpfile.">")
11747 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011748endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011749
11750" ---------------------------------------------------------------------
11751" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011752" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011753fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011754" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011755 if s:user == ""
11756 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11757 else
11758 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11759 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011760 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011761 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011762 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011763 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011764 else
11765 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11766 endif
11767" call Dret("s:MakeSshCmd <".sshcmd.">")
11768 return sshcmd
11769endfun
11770
11771" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011772" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11773fun! s:MakeBookmark(fname)
11774" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11775
11776 if !exists("g:netrw_bookmarklist")
11777 let g:netrw_bookmarklist= []
11778 endif
11779
11780 if index(g:netrw_bookmarklist,a:fname) == -1
11781 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011782 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011783 call add(g:netrw_bookmarklist,a:fname.'/')
11784 elseif a:fname !~ '/'
11785 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11786 else
11787 call add(g:netrw_bookmarklist,a:fname)
11788 endif
11789 call sort(g:netrw_bookmarklist)
11790 endif
11791
11792" call Dret("s:MakeBookmark")
11793endfun
11794
11795" ---------------------------------------------------------------------
11796" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11797fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011798" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011799 " get bookmarks from .netrwbook file
11800 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011801 if filereadable(s:NetrwFile(savefile))
11802" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011803 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011804" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011805 NetrwKeepj call delete(savefile)
11806 endif
11807" call Dret("s:MergeBookmarks")
11808endfun
11809
11810" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011811" s:NetrwBMShow: {{{2
11812fun! s:NetrwBMShow()
11813" call Dfunc("s:NetrwBMShow()")
11814 redir => bmshowraw
11815 menu
11816 redir END
11817 let bmshowlist = split(bmshowraw,'\n')
11818 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011819 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011820 if bmshowfuncs != []
11821 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011822 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011823 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011825 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011826 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011827" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11828endfun
11829
11830" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011831" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011832fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011833 if !exists("w:netrw_liststyle")
11834 let w:netrw_liststyle= g:netrw_liststyle
11835 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011836" 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 +020011837
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011838" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11839
Bram Moolenaaradc21822011-04-01 18:03:16 +020011840 if &ft != "netrw"
11841 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11842 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011843" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011844
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011845 elseif g:netrw_cursor == 8
11846 if w:netrw_liststyle == s:WIDELIST
11847 setl cursorline
11848 setl cursorcolumn
11849 else
11850 setl cursorline
11851 endif
11852 elseif g:netrw_cursor == 7
11853 setl cursorline
11854 elseif g:netrw_cursor == 6
11855 if w:netrw_liststyle == s:WIDELIST
11856 setl cursorline
11857 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011858 elseif g:netrw_cursor == 4
11859 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011860" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011861 setl cursorline
11862 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011863
11864 elseif g:netrw_cursor == 3
11865 " thin-long-tree: cursorline, user's cursorcolumn
11866 " wide : cursorline, cursorcolumn
11867 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011868" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011869 setl cursorline
11870 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011871 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011872" 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 +020011873 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011874 endif
11875
11876 elseif g:netrw_cursor == 2
11877 " thin-long-tree: cursorline, user's cursorcolumn
11878 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011879" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011880 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011881
11882 elseif g:netrw_cursor == 1
11883 " thin-long-tree: user's cursorline, user's cursorcolumn
11884 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011885 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011886" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011887 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011888 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011889" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011890 endif
11891
11892 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011893 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011894" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011895 let &l:cursorline = s:netrw_usercul
11896 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011897 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011898
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011899" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011900" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011901endfun
11902
11903" ---------------------------------------------------------------------
11904" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11905fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011906" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011907 if exists("s:netrw_usercul")
11908 let &l:cursorline = s:netrw_usercul
11909 endif
11910 if exists("s:netrw_usercuc")
11911 let &l:cursorcolumn = s:netrw_usercuc
11912 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011913" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011914" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11915endfun
11916
Christian Brabandt62f7b552024-06-23 20:23:40 +020011917" s:RestoreRegister: restores all registers given in the dict {{{2
11918fun! s:RestoreRegister(dict)
11919 for [key, val] in items(a:dict)
11920 if key == 'unnamed'
11921 let key = ''
11922 endif
11923 call setreg(key, val[0], val[1])
11924 endfor
11925endfun
11926
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011927" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011928" s:NetrwDelete: Deletes a file. {{{2
11929" Uses Steve Hall's idea to insure that Windows paths stay
11930" acceptable. No effect on Unix paths.
11931" Examples of use: let result= s:NetrwDelete(path)
11932fun! s:NetrwDelete(path)
11933" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11934
Bram Moolenaar5c736222010-01-06 20:54:52 +010011935 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011936 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011937 if exists("+shellslash")
11938 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011939 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011940 let result = delete(path)
11941 let &shellslash = sskeep
11942 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011943" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011944 let result= delete(path)
11945 endif
11946 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011947" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011948 let result= delete(path)
11949 endif
11950 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011951 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011952 endif
11953
11954" call Dret("s:NetrwDelete ".result)
11955 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011956endfun
11957
11958" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011959" s:NetrwBufRemover: removes a buffer that: {{{2s
11960" has buffer-id > 1
11961" is unlisted
11962" is unnamed
11963" does not appear in any window
11964fun! s:NetrwBufRemover(bufid)
11965" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11966" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11967" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11968" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11969" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11970
yasuda4dbb2662023-10-04 20:50:35 +020011971 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011972" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011973 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011974 endif
11975
11976" call Dret("s:NetrwBufRemover")
11977endfun
11978
11979" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011980" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011981fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011982" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011983" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011984
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011985 " Clean out the last buffer:
11986 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11987 " If so, delete it.
11988 call s:NetrwBufRemover(bufnr("$"))
11989
Bram Moolenaar446cb832008-06-24 21:56:24 +000011990 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011991" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011992 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11993 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11994 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11995 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11996 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11997 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11998 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11999 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12000 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12001 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12002 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12003 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12004 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12005 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12006 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12007 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12008
Bram Moolenaar85850f32019-07-19 22:05:51 +020012009 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012010" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012011 " when tree listing uses file TreeListing... a new buffer is made.
12012 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012013 " COMBAK: this causes a problem, see P43
12014" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012015 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012016 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012017 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012018" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012019 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012020
Bram Moolenaar446cb832008-06-24 21:56:24 +000012021 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012022" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012023 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12024 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12025 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12026 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12027 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12028 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12029 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12030 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12031 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12032 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12033 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12034 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12035 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12036 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12037 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12038 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12039
Bram Moolenaar5c736222010-01-06 20:54:52 +010012040 if a:0 > 0
12041 let b:netrw_curdir= a:1
12042 if b:netrw_curdir =~ '/$'
12043 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012044 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012045 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012046 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012047 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12048 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012049 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012050 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012051 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012052 endif
12053 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012054 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12055 let &l:bexpr = "netrw#BalloonHelp()"
12056 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012057
Bram Moolenaar8d043172014-01-23 14:24:41 +010012058" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012059endfun
12060
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012061" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012062" s:NetrwExe: executes a string using "!" {{{2
12063fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012064" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010012065 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012066" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012067 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12068 set shell& shellcmdflag& shellxquote& shellxescape&
12069 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010012070 try
12071 exe a:cmd
12072 finally
12073 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12074 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012075 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012076" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012077 exe a:cmd
12078 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012079 if v:shell_error
12080 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12081 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012082" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012083endfun
12084
12085" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012086" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12087fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012088 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012089" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012090 let curbuf = bufnr("%")
12091 let curwin = winnr()
12092 let iwin = 1
12093 while iwin <= winnr("$")
12094 exe iwin."wincmd w"
12095 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12096 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12097 let winvars= w:
12098 break
12099 endif
12100 let iwin= iwin + 1
12101 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012102 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012103 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012104" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012105 for k in keys(winvars)
12106 let w:{k}= winvars[k]
12107 endfor
12108 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012109" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012110 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012111endfun
12112
Bram Moolenaara6878372014-03-22 21:02:50 +010012113" ---------------------------------------------------------------------
12114" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012115" Returns: 0=success
12116" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012117fun! s:NetrwLcd(newdir)
12118" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012119" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012120
Bram Moolenaar85850f32019-07-19 22:05:51 +020012121 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012122 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012123 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012124 catch /^Vim\%((\a\+)\)\=:E344/
12125 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12126 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012127 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012128 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12129 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012130 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012131 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12132 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012133 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012134 endif
12135 endif
12136 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012137 let err472= 1
12138 endtry
12139
12140 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012141 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12142 if exists("w:netrw_prvdir")
12143 let a:newdir= w:netrw_prvdir
12144 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012145 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012146" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012147 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012148" 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 +010012149 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012150 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012151" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12152 return -1
12153 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012154
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012155" call Decho("getcwd <".getcwd().">")
12156" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012157" call Dret("s:NetrwLcd 0")
12158 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012159endfun
12160
Bram Moolenaar9964e462007-05-05 17:54:07 +000012161" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012162" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12163" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12164fun! s:NetrwSaveWordPosn()
12165" call Dfunc("NetrwSaveWordPosn()")
12166 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12167" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12168endfun
12169
12170" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012171" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12172" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12173fun! s:NetrwHumanReadable(sz)
12174" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12175
12176 if g:netrw_sizestyle == 'h'
12177 if a:sz >= 1000000000
12178 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12179 elseif a:sz >= 10000000
12180 let sz = printf("%d",a:sz/1000000)."m"
12181 elseif a:sz >= 1000000
12182 let sz = printf("%.1f",a:sz/1000000.0)."m"
12183 elseif a:sz >= 10000
12184 let sz = printf("%d",a:sz/1000)."k"
12185 elseif a:sz >= 1000
12186 let sz = printf("%.1f",a:sz/1000.0)."k"
12187 else
12188 let sz= a:sz
12189 endif
12190
12191 elseif g:netrw_sizestyle == 'H'
12192 if a:sz >= 1073741824
12193 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12194 elseif a:sz >= 10485760
12195 let sz = printf("%d",a:sz/1048576)."M"
12196 elseif a:sz >= 1048576
12197 let sz = printf("%.1f",a:sz/1048576.0)."M"
12198 elseif a:sz >= 10240
12199 let sz = printf("%d",a:sz/1024)."K"
12200 elseif a:sz >= 1024
12201 let sz = printf("%.1f",a:sz/1024.0)."K"
12202 else
12203 let sz= a:sz
12204 endif
12205
12206 else
12207 let sz= a:sz
12208 endif
12209
12210" call Dret("s:NetrwHumanReadable ".sz)
12211 return sz
12212endfun
12213
12214" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012215" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12216" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12217fun! s:NetrwRestoreWordPosn()
12218" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012219 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012220" call Dret("NetrwRestoreWordPosn")
12221endfun
12222
12223" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012224" s:RestoreBufVars: {{{2
12225fun! s:RestoreBufVars()
12226" call Dfunc("s:RestoreBufVars()")
12227
12228 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12229 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12230 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12231 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12232 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12233 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12234
12235" call Dret("s:RestoreBufVars")
12236endfun
12237
12238" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012239" s:RemotePathAnalysis: {{{2
12240fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012241" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012242
Bram Moolenaara6878372014-03-22 21:02:50 +010012243 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012244 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012245 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012246 let s:user = substitute(a:dirname,dirpat,'\3','')
12247 let s:machine = substitute(a:dirname,dirpat,'\4','')
12248 let s:port = substitute(a:dirname,dirpat,'\5','')
12249 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012250 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012251 if s:machine =~ '@'
12252 let dirpat = '^\(.*\)@\(.\{-}\)$'
12253 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12254 let s:machine = substitute(s:machine,dirpat,'\2','')
12255 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012256
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012257" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12258" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12259" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12260" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12261" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12262" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012263
12264" call Dret("s:RemotePathAnalysis")
12265endfun
12266
12267" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012268" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12269" Returns status
12270" Runs system() on
12271" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012272" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012273fun! s:RemoteSystem(cmd)
12274" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12275 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012276 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 +000012277 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012278 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012279 else
12280 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12281 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12282 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012283 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012284 else
12285 let cmd= cmd.' '
12286 endif
12287 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012288" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012289 let ret= system(cmd)
12290 endif
12291" call Dret("s:RemoteSystem ".ret)
12292 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012293endfun
12294
12295" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012296" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012297fun! s:RestoreWinVars()
12298" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012299 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012300 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12301 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12302 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12303 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12304 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12305 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12306 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12307 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12308 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12309 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12310 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12311 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012312 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12313 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012314 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12315 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12316 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12317" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012318endfun
12319
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012320" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012321" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12322"
12323" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12324" is true) and a command, :Rexplore, which call this function.
12325"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012326" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012327"
12328" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012329fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012330 if exists("s:netrwdrag")
12331 return
12332 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012333" 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 +010012334" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12335" 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 +010012336
12337 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012338 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012339" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012340 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012341 unlet w:netrw_rexfile
12342" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012343 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012344" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12346" 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 +020012347 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012348
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012349 " ---------------------------
12350 " :Rex issued while in a file
12351 " ---------------------------
12352
Bram Moolenaara6878372014-03-22 21:02:50 +010012353 " record current file so :Rex can return to it from netrw
12354 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012355" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012356
12357 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012358" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012359 return
12360 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012361" 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 +020012362 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012363 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012364 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012365 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012366 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012367 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012368 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012369 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012370 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012371" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12372 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012373" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12374 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012375 if exists("s:rexposn_".bufnr('%'))
12376 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012377 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012378 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012380 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012381
Bram Moolenaar85850f32019-07-19 22:05:51 +020012382 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12383 if exists("s:explore_match")
12384 exe "2match netrwMarkFile /".s:explore_match."/"
12385 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012386 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012387
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012388" 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 +010012389" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012390endfun
12391
12392" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012393" s:SaveBufVars: save selected b: variables to s: variables {{{2
12394" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012395fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012396" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012397
12398 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12399 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12400 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12401 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12402 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12403 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12404
12405" call Dret("s:SaveBufVars")
12406endfun
12407
12408" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012409" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12410fun! s:SavePosn(posndict)
12411" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12412
Bram Moolenaar85850f32019-07-19 22:05:51 +020012413 if !exists("a:posndict[bufnr('%')]")
12414 let a:posndict[bufnr("%")]= []
12415 endif
12416" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12417 call add(a:posndict[bufnr("%")],winsaveview())
12418" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012419
12420" call Dret("s:SavePosn posndict")
12421 return a:posndict
12422endfun
12423
12424" ---------------------------------------------------------------------
12425" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12426fun! s:RestorePosn(posndict)
12427" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012428 if exists("a:posndict")
12429 if has_key(a:posndict,bufnr("%"))
12430" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12431 let posnlen= len(a:posndict[bufnr("%")])
12432 if posnlen > 0
12433 let posnlen= posnlen - 1
12434" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12435 call winrestview(a:posndict[bufnr("%")][posnlen])
12436 call remove(a:posndict[bufnr("%")],posnlen)
12437" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12438 endif
12439 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012440 endif
12441" call Dret("s:RestorePosn")
12442endfun
12443
12444" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012445" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012446fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012447" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012448 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12449 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12450 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12451 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12452 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12453 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12454 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12455 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12456 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12457 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12458 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12459 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12460 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12461 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12462 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12463 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12464 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12465 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12466" call Dret("s:SaveWinVars")
12467endfun
12468
12469" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012470" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012471" To allow separate windows to have their own activities, such as
12472" Explore **/pattern, several variables have been made window-oriented.
12473" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012474" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012475" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012476fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012477" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012478 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12479 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12480 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12481 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12482 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12483 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12484 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12485 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12486 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12487 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12488" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012489endfun
12490
12491" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012492" s:SetRexDir: set directory for :Rexplore {{{2
12493fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012494" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012495 let w:netrw_rexdir = a:dirname
12496 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012497 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012498" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12499" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012500" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012501" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012502" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012503endfun
12504
12505" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012506" s:ShowLink: used to modify thin and tree listings to show links {{{2
12507fun! s:ShowLink()
12508" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012509" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12510" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012511 if exists("b:netrw_curdir")
12512 norm! $?\a
12513 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12514 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012515" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12516" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12517" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12518 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012519 let dirlen = strlen(b:netrw_curdir)
12520 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012521" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012522 endif
12523 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012524" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12525" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012526 setl noro ma
12527 call setline(".",modline)
12528 setl ro noma nomod
12529 endif
12530" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12531endfun
12532
12533" ---------------------------------------------------------------------
12534" s:ShowStyle: {{{2
12535fun! s:ShowStyle()
12536 if !exists("w:netrw_liststyle")
12537 let liststyle= g:netrw_liststyle
12538 else
12539 let liststyle= w:netrw_liststyle
12540 endif
12541 if liststyle == s:THINLIST
12542 return s:THINLIST.":thin"
12543 elseif liststyle == s:LONGLIST
12544 return s:LONGLIST.":long"
12545 elseif liststyle == s:WIDELIST
12546 return s:WIDELIST.":wide"
12547 elseif liststyle == s:TREELIST
12548 return s:TREELIST.":tree"
12549 else
12550 return 'n/a'
12551 endif
12552endfun
12553
12554" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012555" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12556" Solution from Nicolai Weibull, vim docs (:help strlen()),
12557" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012558fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012559" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12560
12561 if v:version >= 703 && exists("*strdisplaywidth")
12562 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012563
Bram Moolenaar8d043172014-01-23 14:24:41 +010012564 elseif type(g:Align_xstrlen) == 1
12565 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12566 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012567
Bram Moolenaar8d043172014-01-23 14:24:41 +010012568 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012569 " number of codepoints (Latin a + combining circumflex is two codepoints)
12570 " (comment from TM, solution from NW)
12571 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012572
Bram Moolenaar8d043172014-01-23 14:24:41 +010012573 elseif g:Align_xstrlen == 2
12574 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012575 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12576 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012577 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012578
Bram Moolenaar8d043172014-01-23 14:24:41 +010012579 elseif g:Align_xstrlen == 3
12580 " virtual length (counting, for instance, tabs as anything between 1 and
12581 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012582 " preceded by lam, one otherwise, etc.)
12583 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012584 let modkeep= &l:mod
12585 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012586 call setline(line("."),a:x)
12587 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012588 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012589 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012590 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591
Bram Moolenaar446cb832008-06-24 21:56:24 +000012592 else
12593 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012594 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012595 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012596" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012597 return ret
12598endfun
12599
12600" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012601" s:ShellEscape: shellescape(), or special windows handling {{{2
12602fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012603 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012604 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12605 endif
12606 let f = a:0 > 0 ? a:1 : 0
12607 return shellescape(a:s, f)
12608endfun
12609
12610" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012611" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012612fun! s:TreeListMove(dir)
12613" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012614 let curline = getline('.')
12615 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12616 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12617 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12618 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12619 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12620 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12621" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12622" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12623" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12624" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12625" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12626 " COMBAK : need to handle when on a directory
12627 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012628 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012629 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012630 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012631 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012632" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012633 elseif a:dir == '[]' && nxtline != ''
12634 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012635" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012636 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12637 if nl != 0
12638 NetrwKeepj norm! k
12639 else
12640 NetrwKeepj norm! G
12641 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012642" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012643 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012644 endif
12645
12646" call Dret("s:TreeListMove")
12647endfun
12648
12649" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012650" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12651" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12652" can't be called except via emenu. But due to locale, that menu line may not be called
12653" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12654fun! s:UpdateBuffersMenu()
12655" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012656 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012657 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012658 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012659 catch /^Vim\%((\a\+)\)\=:E/
12660 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012661 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012662 endtry
12663 endif
12664" call Dret("s:UpdateBuffersMenu")
12665endfun
12666
12667" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012668" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012669" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012670fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012671" call Dfunc("s:UseBufWinVars()")
12672 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012673 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12674 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12675 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12676 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12677 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12678 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12679 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12680 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12681 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 +000012682" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012683endfun
12684
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012685" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012686" s:UserMaps: supports user-defined UserMaps {{{2
12687" * calls a user-supplied funcref(islocal,curdir)
12688" * interprets result
12689" See netrw#UserMaps()
12690fun! s:UserMaps(islocal,funcname)
12691" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12692
12693 if !exists("b:netrw_curdir")
12694 let b:netrw_curdir= getcwd()
12695 endif
12696 let Funcref = function(a:funcname)
12697 let result = Funcref(a:islocal)
12698
12699 if type(result) == 1
12700 " if result from user's funcref is a string...
12701" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12702 if result == "refresh"
12703" call Decho("refreshing display",'~'.expand("<slnum>"))
12704 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12705 elseif result != ""
12706" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12707 exe result
12708 endif
12709
12710 elseif type(result) == 3
12711 " if result from user's funcref is a List...
12712" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12713 for action in result
12714 if action == "refresh"
12715" call Decho("refreshing display",'~'.expand("<slnum>"))
12716 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12717 elseif action != ""
12718" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12719 exe action
12720 endif
12721 endfor
12722 endif
12723
12724" call Dret("s:UserMaps")
12725endfun
12726
Bram Moolenaar85850f32019-07-19 22:05:51 +020012727" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012728" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012729" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012730let &cpo= s:keepcpo
12731unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012732
Bram Moolenaar85850f32019-07-19 22:05:51 +020012733" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012734" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012735" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012736" vim:ts=8 fdm=marker