blob: 17c4a6695fd8401bfd693807c0b4605f3e370402 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
Travis Sheltone34d0e32024-07-30 21:08:56 +020024" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010025" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000026" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010027" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000028" Permission is hereby granted to use and distribute this code,
29" with or without modifications, provided that this copyright
30" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000031" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000032" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000033" expressed or implied. By using this plugin, you agree that
34" in no event will the copyright holder be liable for any damages
35" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010036"
37" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
38" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
39"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020040"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000041"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000042" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000043" (James 1:22 RSV)
44" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000045" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000046if &cp || exists("g:loaded_netrw")
47 finish
48endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020049
50" Check that vim has patches that netrw requires.
51" Patches needed for v7.4: 1557, and 213.
52" (netrw will benefit from vim's having patch#656, too)
53let s:needspatches=[1557,213]
54if exists("s:needspatches")
55 for ptch in s:needspatches
56 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
57 if !exists("s:needpatch{ptch}")
58 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
59 endif
60 let s:needpatch{ptch}= 1
61 finish
62 endif
63 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020064endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020065
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010066let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000067
Bram Moolenaar1afcace2005-11-25 19:54:28 +000068let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010069setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020070"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010071"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010072"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000074" ======================
75" Netrw Variables: {{{1
76" ======================
77
Bram Moolenaar071d4272004-06-13 20:20:40 +000078" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020079" netrw#ErrorMsg: {{{2
80" 0=note = s:NOTE
81" 1=warning = s:WARNING
82" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010083" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
84" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
85" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010086" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020087fun! netrw#ErrorMsg(level,msg,errnum)
88" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
89
90 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020091" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020092 return
93 endif
94
95 if a:level == 1
96 let level= "**warning** (netrw) "
97 elseif a:level == 2
98 let level= "**error** (netrw) "
99 else
100 let level= "**note** (netrw) "
101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100102" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103
Damienb4d11642024-08-15 22:00:45 +0200104 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200105 " use popup window
106 if type(a:msg) == 3
107 let msg = [level]+a:msg
108 else
109 let msg= level.a:msg
110 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200111 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200112 let s:popuperr_text= ""
113 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200114 " (default) netrw creates a one-line window to show error/warning
115 " messages (reliably displayed)
116
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100117 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100119" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120
121 " getting messages out reliably is just plain difficult!
122 " This attempt splits the current window, creating a one line window.
123 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100124" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100126" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100128 if type(a:msg) == 3
129 for msg in a:msg
130 NetrwKeepj call setline(line("$")+1,level.msg)
131 endfor
132 else
133 NetrwKeepj call setline(line("$")+1,level.a:msg)
134 endif
135 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100137" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 bo 1split
139 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200140 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100142 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100143" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100145 if type(a:msg) == 3
146 for msg in a:msg
147 NetrwKeepj call setline(line("$")+1,level.msg)
148 endfor
149 else
150 NetrwKeepj call setline(line("$"),level.a:msg)
151 endif
152 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100154" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155 if &fo !~ '[ta]'
156 syn clear
157 syn match netrwMesgNote "^\*\*note\*\*"
158 syn match netrwMesgWarning "^\*\*warning\*\*"
159 syn match netrwMesgError "^\*\*error\*\*"
160 hi link netrwMesgWarning WarningMsg
161 hi link netrwMesgError Error
162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100163" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200164 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200165
166 else
167 " (optional) netrw will show messages using echomsg. Even if the
168 " message doesn't appear, at least it'll be recallable via :messages
169" redraw!
170 if a:level == s:WARNING
171 echohl WarningMsg
172 elseif a:level == s:ERROR
173 echohl Error
174 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100175
176 if type(a:msg) == 3
177 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100178 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100179 endfor
180 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100181 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100182 endif
183
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100184" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200185 echohl None
186 endif
187
188" call Dret("netrw#ErrorMsg")
189endfun
190
191" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100192" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100193" Loosely, varname = value.
194fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100195" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100196 if !exists(a:varname)
197 if type(a:value) == 0
198 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200199 elseif type(a:value) == 1 && a:value =~ '^[{[]'
200 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100201 elseif type(a:value) == 1
202 exe "let ".a:varname."="."'".a:value."'"
203 else
204 exe "let ".a:varname."=".a:value
205 endif
206 endif
207endfun
208
209" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000210" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200211call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000212if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100213 call s:NetrwInit("s:THINLIST",0)
214 call s:NetrwInit("s:LONGLIST",1)
215 call s:NetrwInit("s:WIDELIST",2)
216 call s:NetrwInit("s:TREELIST",3)
217 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000218endif
219
Damien7c754112024-08-15 21:58:57 +0200220let s:NOTE = 0
221let s:WARNING = 1
222let s:ERROR = 2
223call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
224
Bram Moolenaar9964e462007-05-05 17:54:07 +0000225" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200226" Default option values: {{{2
227let g:netrw_localcopycmdopt = ""
228let g:netrw_localcopydircmdopt = ""
229let g:netrw_localmkdiropt = ""
230let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200231
232" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000233" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200234if exists("*popup_atcursor")
235\ && has("syntax")
236\ && exists("g:syntax_on")
237\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200238 call s:NetrwInit("g:netrw_use_errorwindow",2)
239else
240 call s:NetrwInit("g:netrw_use_errorwindow",1)
241endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200242
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000243if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100244 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000245 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100246 elseif executable("curl")
247 let g:netrw_dav_cmd = "curl"
248 else
249 let g:netrw_dav_cmd = ""
250 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000251endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000252if !exists("g:netrw_fetch_cmd")
253 if executable("fetch")
254 let g:netrw_fetch_cmd = "fetch -o"
255 else
256 let g:netrw_fetch_cmd = ""
257 endif
258endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100259if !exists("g:netrw_file_cmd")
260 if executable("elinks")
261 call s:NetrwInit("g:netrw_file_cmd","elinks")
262 elseif executable("links")
263 call s:NetrwInit("g:netrw_file_cmd","links")
264 endif
265endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000266if !exists("g:netrw_ftp_cmd")
267 let g:netrw_ftp_cmd = "ftp"
268endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200269let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200270if !exists("g:netrw_ftp_options")
271 let g:netrw_ftp_options= "-i -n"
272endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000273if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100274 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100275 let g:netrw_http_cmd = "wget"
276 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100277 elseif executable("curl")
278 let g:netrw_http_cmd = "curl"
279 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200280 elseif executable("elinks")
281 let g:netrw_http_cmd = "elinks"
282 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000283 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100284 let g:netrw_http_cmd = "fetch"
285 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200286 elseif executable("links")
287 let g:netrw_http_cmd = "links"
288 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000289 else
290 let g:netrw_http_cmd = ""
291 endif
292endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100293call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100294call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100295call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
296call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200297call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200298if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200299 if executable("scp")
300 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
301 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200302 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200303 else
304 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
305 endif
306endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100307call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
308call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000309
Nir Lichtman1e34b952024-05-08 19:19:34 +0200310if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000311 \ && exists("g:netrw_use_nt_rcp")
312 \ && g:netrw_use_nt_rcp
313 \ && executable( $SystemRoot .'/system32/rcp.exe')
314 let s:netrw_has_nt_rcp = 1
315 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000316else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000317 let s:netrw_has_nt_rcp = 0
318 let s:netrw_rcpmode = ''
319endif
320
321" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000322" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000323" Cygwin Detection ------- {{{3
324if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200325 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
326 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000327 else
328 let g:netrw_cygwin= 0
329 endif
330endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000331" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100332call s:NetrwInit("g:netrw_alto" , &sb)
333call s:NetrwInit("g:netrw_altv" , &spr)
334call s:NetrwInit("g:netrw_banner" , 1)
335call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200336call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100337call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200338call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100339call s:NetrwInit("g:netrw_compress" , "gzip")
340call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200341if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
342 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
343 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000344endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200345call s:NetrwInit("g:netrw_cursor" , 2)
346let s:netrw_usercul = &cursorline
347let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200348"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100349call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000350" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200351call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200352call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200353call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100354call s:NetrwInit("g:netrw_dirhistmax" , 10)
355call s:NetrwInit("g:netrw_fastbrowse" , 1)
356call 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 +0000357if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000358 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
359 let g:netrw_ftp_list_cmd = "ls -lF"
360 let g:netrw_ftp_timelist_cmd = "ls -tlF"
361 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000362 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363 let g:netrw_ftp_list_cmd = "dir"
364 let g:netrw_ftp_timelist_cmd = "dir"
365 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000366 endif
367endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100368call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000369" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100370call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371if !exists("g:netrw_ignorenetrc")
372 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
373 let g:netrw_ignorenetrc= 1
374 else
375 let g:netrw_ignorenetrc= 0
376 endif
377endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100378call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000379if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000380 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100381 if exists("g:netrw_list_cmd_options")
382 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
383 else
384 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
385 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000386 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200387 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100388 if exists("g:netrw_list_cmd_options")
389 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
390 else
391 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
392 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000393 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100394" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000395 let g:netrw_list_cmd= ""
396 endif
397endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100398call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000399" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200400if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200401 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200402 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
403endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100404if !exists("g:netrw_localcmdshell")
405 let g:netrw_localcmdshell= ""
406endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000407if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200408 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000409 if g:netrw_cygwin
410 let g:netrw_localcopycmd= "cp"
411 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000412 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200413 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000414 endif
415 elseif has("unix") || has("macunix")
416 let g:netrw_localcopycmd= "cp"
417 else
418 let g:netrw_localcopycmd= ""
419 endif
420endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100421if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200422 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 let g:netrw_localcopydircmd = "cp"
425 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100426 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000427 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200428 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200430 elseif has("unix")
431 let g:netrw_localcopydircmd = "cp"
432 let g:netrw_localcopydircmdopt= " -R"
433 elseif has("macunix")
434 let g:netrw_localcopydircmd = "cp"
435 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200437 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100438 endif
439endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200440if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100441 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200442 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
443endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200444if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200445 if g:netrw_cygwin
446 call s:NetrwInit("g:netrw_localmkdir","mkdir")
447 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000448 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200449 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200450 endif
451else
452 call s:NetrwInit("g:netrw_localmkdir","mkdir")
453endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200454call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200455if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200456 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200457 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
458endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000459if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200460 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000461 if g:netrw_cygwin
462 let g:netrw_localmovecmd= "mv"
463 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000464 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200465 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000466 endif
467 elseif has("unix") || has("macunix")
468 let g:netrw_localmovecmd= "mv"
469 else
470 let g:netrw_localmovecmd= ""
471 endif
472endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100473" following serves as an example for how to insert a version&patch specific test
474"if v:version < 704 || (v:version == 704 && !has("patch1107"))
475"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
477" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000478if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000479 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000480endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000481if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000482 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
483endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000484" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100485call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
486call s:NetrwInit("g:netrw_maxfilenamelen", 32)
487call s:NetrwInit("g:netrw_menu" , 1)
488call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200489call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_retmap" , 0)
491if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
492 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200493elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100494 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
495else
496 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000497endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100498call s:NetrwInit("g:netrw_preview" , 0)
499call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100500call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100501call s:NetrwInit("g:netrw_sshport" , "-p")
502call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
503call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
504call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100505call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
506" Default values - q-s ---------- {{{3
507call s:NetrwInit("g:netrw_quickhelp",0)
508let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100509 \ "(create new) %:file d:directory",
510 \ "(windows split&open) o:horz v:vert p:preview",
511 \ "i:style qf:file info O:obtain r:reverse",
512 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
513 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
514 \ "(history) qb:list u:go up U:go down",
515 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
517call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100518if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
519 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
520else
521 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
522endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
524call s:NetrwInit("g:netrw_sort_options" , "")
525call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000526if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200528 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529 else
530 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000531 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000532endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533call s:NetrwInit("g:netrw_special_syntax" , 0)
534call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200535call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100536call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100537call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000538" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100539call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200540if !exists("g:netrw_xstrlen")
541 if exists("g:Align_xstrlen")
542 let g:netrw_xstrlen= g:Align_xstrlen
543 elseif exists("g:drawit_xstrlen")
544 let g:netrw_xstrlen= g:drawit_xstrlen
545 elseif &enc == "latin1" || !has("multi_byte")
546 let g:netrw_xstrlen= 0
547 else
548 let g:netrw_xstrlen= 1
549 endif
550endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100551call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200552call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100553call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200554if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000555" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000556" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100557call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200558if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200559 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200560else
Bram Moolenaarff034192013-04-24 18:51:19 +0200561 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200562endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200563call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100564call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
565call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100566if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100567 let s:treedepthstring= "│ "
568else
569 let s:treedepthstring= "| "
570endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200571call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000572
573" BufEnter event ignored by decho when following variable is true
574" Has a side effect that doau BufReadPost doesn't work, so
575" files read by network transfer aren't appropriately highlighted.
576"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577
Bram Moolenaaradc21822011-04-01 18:03:16 +0200578" ======================
579" Netrw Initialization: {{{1
580" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200581if 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 +0100582" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100583 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200584" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100585 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100586 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
587 au VimEnter * let s:initbeval= &beval
588"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100589" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
590" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
591" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
592" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
593" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
594" 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 +0200595endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200596au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200597
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200598if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100599 com! -nargs=* NetrwKeepj keepj <args>
600else
601 let g:netrw_keepj= ""
602 com! -nargs=* NetrwKeepj <args>
603endif
604
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000605" ==============================
606" Netrw Utility Functions: {{{1
607" ==============================
608
Bram Moolenaaradc21822011-04-01 18:03:16 +0200609" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100610" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100611if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100612" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100613 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100614 if &ft != "netrw"
615 return ""
616 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200617 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
618 " popup error window is still showing
619 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
620 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
621 " text under mouse hasn't changed; only close window when it changes
622 call popup_close(s:popuperr_id)
623 unlet s:popuperr_text
624 else
625 let s:popuperr_text= v:beval_text
626 endif
627 let mesg= ""
628 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 +0100629 let mesg= ""
630 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
631 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
632 elseif getline(v:beval_lnum) =~ '^"\s*/'
633 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
634 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100635 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100636 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
637 let mesg = "S: edit sorting sequence"
638 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
639 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
640 elseif v:beval_text == "Quick" || v:beval_text == "Help"
641 let mesg = "Help: press <F1>"
642 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
643 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
644 else
645 let mesg= ""
646 endif
647 return mesg
648 endfun
649"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100650" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
651" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
652" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
653" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
654" 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 +0200655endif
656
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200658" netrw#Explore: launch the local browser in the directory of the current file {{{2
659" indx: == -1: Nexplore
660" == -2: Pexplore
661" == +: this is overloaded:
662" * If Nexplore/Pexplore is in use, then this refers to the
663" indx'th item in the w:netrw_explore_list[] of items which
664" matched the */pattern **/pattern *//pattern **//pattern
665" * If Hexplore or Vexplore, then this will override
666" g:netrw_winsize to specify the qty of rows or columns the
667" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100668" 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 +0200669" dosplit==1: the window will be split before running the local browser
670" style == 0: Explore style == 1: Explore!
671" == 2: Hexplore style == 3: Hexplore!
672" == 4: Vexplore style == 5: Vexplore!
673" == 6: Texplore
674fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100675" 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 +0100676" 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 +0200677 if !exists("b:netrw_curdir")
678 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100679" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200680 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100681
682 " record current file for Rexplore's benefit
683 if &ft != "netrw"
684 let w:netrw_rexfile= expand("%:p")
685 endif
686
687 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200688 let curdir = simplify(b:netrw_curdir)
689 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200690 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200691 let curdir= substitute(curdir,'\','/','g')
692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100693" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100694
695 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
696 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
697 " try Explore again.
698 if a:0 > 0
699" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100700 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
701 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
702 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
703 \ '~'.expand("<slnum>"))
704 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200705 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
706 if a1 != a:1
707 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
708 return
709 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100710 endif
711 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200712
713 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200714 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100715" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100716 sil! let keepregstar = @*
717 sil! let keepregplus = @+
718 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200719 sil! let keepregslash= @/
720
Bram Moolenaar8d043172014-01-23 14:24:41 +0100721 " if dosplit
722 " -or- file has been modified AND file not hidden when abandoned
723 " -or- Texplore used
724 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 call s:SaveWinVars()
726 let winsz= g:netrw_winsize
727 if a:indx > 0
728 let winsz= a:indx
729 endif
730
731 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200733 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200734 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200735
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200736 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200737 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200738 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200739 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
741 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200744 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200747 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200748 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200749 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200752 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200753 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200754 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200758 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200759 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 6 " Texplore
762 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 exe "keepalt tabnew ".fnameescape(curdir)
764 call s:RestoreBufVars()
765 endif
766 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100768 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200769
770 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100773" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
779 if dirname !~ '/$'
780 let dirname= dirname."/"
781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.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 ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200787 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let dirname= a:1
794 endif
795 else
796 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 call s:NetrwClearExplore()
799" call Dret("netrw#Explore : cleared list")
800 return
801 endif
802
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 if dirname =~ '\.\./\=$'
805 let dirname= simplify(fnamemodify(dirname,':p:h'))
806 elseif dirname =~ '\.\.' || dirname == '.'
807 let dirname= simplify(fnamemodify(dirname,':p'))
808 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100809" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810
811 if dirname =~ '^\*//'
812 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
815 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
818
819 elseif dirname =~ '^\*\*//'
820 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 let pattern= substitute(dirname,'^\*\*//','','')
823 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825
826 elseif dirname =~ '/\*\*/'
827 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200830 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 let b:netrw_curdir = prefixdir
832 else
833 let b:netrw_curdir= getcwd().'/'.prefixdir
834 endif
835 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
836 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
838" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839
840 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200841 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100843" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200844
845 elseif dirname=~ '^\*\*/'
846 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
847 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100848" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 else
851 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 endif
854
855 if starpat == 0 && a:indx >= 0
856 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100857" 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 +0200858 if dirname == ""
859 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200861 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200862 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200863 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200865 if dirname == ""
866 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200867 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100869 " depending on whether backslashes have been converted to forward slashes by earlier code).
870 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200871 let dirname= b:netrw_curdir."/".dirname
872 endif
873 elseif dirname !~ '^/'
874 let dirname= b:netrw_curdir."/".dirname
875 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100876" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100878" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
879" 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 +0200880 endif
881 if exists("w:netrw_bannercnt")
882 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
883 " If one wants to return the same place in the netrw window, use :Rex instead.
884 exe w:netrw_bannercnt
885 endif
886
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200888 " ---------------------------------------------------------------------
889 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
890" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100891" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200892" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100893" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200894" endif
895 " ---------------------------------------------------------------------
896
897 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
898 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
899 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
900 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
901 elseif a:indx <= 0
902 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100903" 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 +0200904 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100905" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200906 let s:didstarstar= 1
907 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
908 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
909 endif
910
911 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100912" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200913 if !exists("w:netrw_explore_indx")
914 let w:netrw_explore_indx= 0
915 endif
916
917 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200919
920 if indx == -1
921 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100924 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 +0200925 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100926" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100927 if @* != keepregstar | sil! let @* = keepregstar | endif
928 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100929 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200930 sil! let @/ = keepregslash
931" call Dret("netrw#Explore")
932 return
933 endif
934 let indx= w:netrw_explore_indx
935 if indx < 0 | let indx= 0 | endif
936 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
937 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100938" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
940 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100941" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200942 endwhile
943 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100944" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200945
946 elseif indx == -2
947 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100950 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 +0200951 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100952" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100953 if @* != keepregstar | sil! let @* = keepregstar | endif
954 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100955 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 sil! let @/ = keepregslash
957" call Dret("netrw#Explore")
958 return
959 endif
960 let indx= w:netrw_explore_indx
961 if indx < 0 | let indx= 0 | endif
962 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
963 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100964" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 while indx >= 0 && curfile == w:netrw_explore_list[indx]
966 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100967" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200968 endwhile
969 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100970" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200971
972 else
973 " Explore -- initialize
974 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100976 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200977 let w:netrw_explore_indx= 0
978 if !exists("b:netrw_curdir")
979 let b:netrw_curdir= getcwd()
980 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200982
983 " switch on starpat to build the w:netrw_explore_list of files
984 if starpat == 1
985 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
987" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100989 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 catch /^Vim\%((\a\+)\)\=:E480/
991 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
992" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
993 return
994 endtry
995 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
996 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
997
998 elseif starpat == 2
999 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001000" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1001" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001003 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001004 catch /^Vim\%((\a\+)\)\=:E480/
1005 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1006 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001007 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001008" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001009 if @* != keepregstar | sil! let @* = keepregstar | endif
1010 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001011 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 sil! let @/ = keepregslash
1013" call Dret("netrw#Explore : no files matched pattern")
1014 return
1015 endtry
1016 let s:netrw_curdir = b:netrw_curdir
1017 let w:netrw_explore_list = getqflist()
1018 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1019 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1020
1021 elseif starpat == 3
1022 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001023" 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 +02001024 let filepat= substitute(dirname,'^\*/','','')
1025 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001026" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1027" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001028 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1029 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1030
1031 elseif starpat == 4
1032 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" 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 +02001034 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1035 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1036 endif " switch on starpat to build w:netrw_explore_list
1037
1038 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1040" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001041
1042 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001043 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001044 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001045" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001046 if @* != keepregstar | sil! let @* = keepregstar | endif
1047 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001048 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001049 sil! let @/ = keepregslash
1050" call Dret("netrw#Explore : no files matched")
1051 return
1052 endif
1053 endif " if indx ... endif
1054
1055 " NetrwStatusLine support - for exploring support
1056 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001057" 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 +02001058
1059 " wrap the indx around, but issue a note
1060 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001061" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1063 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001064 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001065 endif
1066
1067 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 call netrw#LocalBrowseCheck(newdir)
1074 if !exists("w:netrw_liststyle")
1075 let w:netrw_liststyle= g:netrw_liststyle
1076 endif
1077 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001078 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001080 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 endif
1082 let w:netrw_explore_mtchcnt = indx + 1
1083 let w:netrw_explore_bufnr = bufnr("%")
1084 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001085 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001086" 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 +02001087
1088 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001089" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 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 +02001092 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001093 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001094" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001095 if @* != keepregstar | sil! let @* = keepregstar | endif
1096 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001097 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001098 sil! let @/ = keepregslash
1099" call Dret("netrw#Explore : missing +path_extra")
1100 return
1101 endif
1102
1103 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001104" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001105 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1106 sil! unlet w:netrw_treedict
1107 sil! unlet w:netrw_treetop
1108 endif
1109 let newdir= dirname
1110 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001111 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001112 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001113 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 endif
1115 endif
1116
1117 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001118" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1119" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001121" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001123 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001124" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 let s:explore_prvdir = b:netrw_curdir
1126 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001127 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 if b:netrw_curdir !~ '/$'
1129 let dirlen= dirlen + 1
1130 endif
1131 let prvfname= ""
1132 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001133" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001134 if fname =~ '^'.b:netrw_curdir
1135 if s:explore_match == ""
1136 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1137 else
1138 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1139 endif
1140 elseif fname !~ '^/' && fname != prvfname
1141 if s:explore_match == ""
1142 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1143 else
1144 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1145 endif
1146 endif
1147 let prvfname= fname
1148 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001149" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001150 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1151 exe "2match netrwMarkFile /".s:explore_match."/"
1152 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001153 endif
1154 echo "<s-up>==Pexplore <s-down>==Nexplore"
1155 else
1156 2match none
1157 if exists("s:explore_match") | unlet s:explore_match | endif
1158 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001159" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001160 endif
1161
Bram Moolenaara6878372014-03-22 21:02:50 +01001162 " since Explore may be used to initialize netrw's browser,
1163 " there's no danger of a late FocusGained event on initialization.
1164 " Consequently, set s:netrw_events to 2.
1165 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001166 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001167" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001168 if @* != keepregstar | sil! let @* = keepregstar | endif
1169 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001170 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001171 sil! let @/ = keepregslash
1172" call Dret("netrw#Explore : @/<".@/.">")
1173endfun
1174
1175" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001176" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001177" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1178" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1179" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1180" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1181" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001182fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001183" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001184 let curwin= winnr()
1185
Bram Moolenaara6878372014-03-22 21:02:50 +01001186 if a:0 > 0 && a:1 != ""
1187 " if a netrw window is already on the left-side of the tab
1188 " and a directory has been specified, explore with that
1189 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001190" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001192" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001193 exe "1wincmd w"
1194 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001195" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001196 exe "Explore ".fnameescape(a1)
1197 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001198 let s:lexplore_win= curwin
1199 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001201" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 unlet t:netrw_lexposn
1203 endif
1204" call Dret("netrw#Lexplore")
1205 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001206 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 exe curwin."wincmd w"
1208 else
1209 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001210" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001211 endif
1212
Bram Moolenaar8d043172014-01-23 14:24:41 +01001213 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001215 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001216" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 else
1218 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001219" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222
1223 if lexwinnr > 0
1224 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226 exe lexwinnr."wincmd w"
1227 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001228 let t:netrw_lexposn = winsaveview()
1229" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001230" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 close
1232 if lexwinnr < curwin
1233 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001234 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001235 if lexwinnr != curwin
1236 exe curwin."wincmd w"
1237 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001238 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001239" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001240
1241 else
1242 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001243" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244 exe "1wincmd w"
1245 let keep_altv = g:netrw_altv
1246 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001247 if a:count != 0
1248 let netrw_winsize = g:netrw_winsize
1249 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001251 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001252" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001253 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 +02001254" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001257 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001259 elseif curfile =~ '^\a\{3,}://'
1260" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001261 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001264 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 endif
1266 if a:count != 0
1267 let g:netrw_winsize = netrw_winsize
1268 endif
1269 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001270 let g:netrw_altv = keep_altv
1271 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001272 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1273 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001274 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001275 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001276" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1277" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001278 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001279" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001280" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1281 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001282 unlet t:netrw_lexposn
1283 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001284 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001285
1286 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001287 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288 if a:rightside
1289 let g:netrw_chgwin= 1
1290 else
1291 let g:netrw_chgwin= 2
1292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001293" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295
Bram Moolenaar8d043172014-01-23 14:24:41 +01001296" call Dret("netrw#Lexplore")
1297endfun
1298
1299" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001300" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001301" supports :NetrwClean -- remove netrw from first directory on runtimepath
1302" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001303fun! netrw#Clean(sys)
1304" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001305
1306 if a:sys
1307 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1308 else
1309 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1310 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001311" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001312 let diddel= 0
1313 let diddir= ""
1314
1315 if choice == 1
1316 for dir in split(&rtp,',')
1317 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001318" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001319 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1320 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1321 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1322 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1323 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1324 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 +00001325 let diddir= dir
1326 let diddel= diddel + 1
1327 if !a:sys|break|endif
1328 endif
1329 endfor
1330 endif
1331
1332 echohl WarningMsg
1333 if diddel == 0
1334 echomsg "netrw is either not installed or not removable"
1335 elseif diddel == 1
1336 echomsg "removed one copy of netrw from <".diddir.">"
1337 else
1338 echomsg "removed ".diddel." copies of netrw"
1339 endif
1340 echohl None
1341
Bram Moolenaara6878372014-03-22 21:02:50 +01001342" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001343endfun
1344
Bram Moolenaar5c736222010-01-06 20:54:52 +01001345" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001346" netrw#MakeTgt: make a target out of the directory name provided {{{2
1347fun! netrw#MakeTgt(dname)
1348" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1349 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001350 let svpos = winsaveview()
1351" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001352 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1353" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001354 if s:netrwmftgt_islocal
1355 let netrwmftgt= simplify(a:dname)
1356 else
1357 let netrwmftgt= a:dname
1358 endif
1359 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1360 " re-selected target, so just clear it
1361 unlet s:netrwmftgt s:netrwmftgt_islocal
1362 else
1363 let s:netrwmftgt= netrwmftgt
1364 endif
1365 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001366 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001367 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001368" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1369 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001370" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001371endfun
1372
Bram Moolenaara6878372014-03-22 21:02:50 +01001373" ---------------------------------------------------------------------
1374" netrw#Obtain: {{{2
1375" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001376" islocal=0 obtain from remote source
1377" =1 obtain from local source
1378" fname : a filename or a list of filenames
1379" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001380fun! netrw#Obtain(islocal,fname,...)
1381" 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 +02001382 " NetrwStatusLine support - for obtaining support
1383
1384 if type(a:fname) == 1
1385 let fnamelist= [ a:fname ]
1386 elseif type(a:fname) == 3
1387 let fnamelist= a:fname
1388 else
1389 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 +01001390" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001391 return
1392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001393" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001394 if a:0 > 0
1395 let tgtdir= a:1
1396 else
1397 let tgtdir= getcwd()
1398 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001399" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400
1401 if exists("b:netrw_islocal") && b:netrw_islocal
1402 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1405 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001406 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001411 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 if v:shell_error != 0
1413 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 +01001414" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 return
1416 endif
1417 endfor
1418 else
1419 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1421 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1422" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001423 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 if v:shell_error != 0
1425 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 +01001426" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 return
1428 endif
1429 endif
1430 elseif !exists("b:netrw_curdir")
1431 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1432 else
1433 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1434 endif
1435
1436 else
1437 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001438" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001439 if type(a:fname) == 1
1440 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1441 endif
1442 call s:NetrwMethod(b:netrw_curdir)
1443
1444 if b:netrw_method == 4
1445 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001447 if exists("g:netrw_port") && g:netrw_port != ""
1448 let useport= " ".g:netrw_scpport." ".g:netrw_port
1449 else
1450 let useport= ""
1451 endif
1452 if b:netrw_fname =~ '/'
1453 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1454 else
1455 let path= ""
1456 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001457 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001458 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 +02001459
1460 elseif b:netrw_method == 2
1461 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001463 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001464 let tmpbufnr= bufnr("%")
1465 setl ff=unix
1466 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001467 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001469 endif
1470
1471 if exists("b:netrw_fname") && b:netrw_fname != ""
1472 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 endif
1475
1476 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001477 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 endif
1480 for fname in fnamelist
1481 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001482" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001483 endfor
1484 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485 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 +02001486 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001487 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 endif
1489 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1490 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1491 let debugkeep= &debug
1492 setl debug=msg
1493 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1494 let &debug= debugkeep
1495 endif
1496
1497 elseif b:netrw_method == 3
1498 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001500 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 let tmpbufnr= bufnr("%")
1502 setl ff=unix
1503
1504 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001506" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001507 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001508 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001509" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001510 endif
1511
1512 if exists("g:netrw_uid") && g:netrw_uid != ""
1513 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001515" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
1524 endif
1525
1526 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 endif
1530
1531 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 endif
1535
1536 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540
1541 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001546 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001547 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549
1550 " perform ftp:
1551 " -i : turns off interactive prompting from ftp
1552 " -n unix : DON'T use <.netrc>, even though it exists
1553 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001554 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1555 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001556 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1558 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001559" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001561 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 endif
1563 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001564
1565 elseif b:netrw_method == 9
1566 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001567" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001568 if a:fname =~ '/'
1569 let localfile= substitute(a:fname,'^.*/','','')
1570 else
1571 let localfile= a:fname
1572 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001573 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 +02001574
Bram Moolenaarff034192013-04-24 18:51:19 +02001575 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001576 " probably a badly formed url; protocol not recognized
1577" call Dret("netrw#Obtain : unsupported method")
1578 return
1579
1580 else
1581 " protocol recognized but not supported for Obtain (yet?)
1582 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001583 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001584 endif
1585" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001586 return
1587 endif
1588
1589 " restore status line
1590 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001591 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001592 endif
1593
1594 endif
1595
1596 " cleanup
1597 if exists("tmpbufnr")
1598 if bufnr("%") != tmpbufnr
1599 exe tmpbufnr."bw!"
1600 else
1601 q!
1602 endif
1603 endif
1604
Bram Moolenaara6878372014-03-22 21:02:50 +01001605" call Dret("netrw#Obtain")
1606endfun
1607
1608" ---------------------------------------------------------------------
1609" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1610fun! netrw#Nread(mode,fname)
1611" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001612 let svpos= winsaveview()
1613" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001614 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001615" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1616 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001617
1618 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1619 if exists("w:netrw_bannercnt")
1620 " start with cursor just after the banner
1621 exe w:netrw_bannercnt
1622 endif
1623 endif
1624" call Dret("netrw#Nread")
1625endfun
1626
1627" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001628" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1629" Options get restored by s:NetrwOptionsRestore()
1630"
1631" Option handling:
1632" * save user's options (s:NetrwOptionsSave)
1633" * set netrw-safe options (s:NetrwOptionsSafe)
1634" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1635" * restore user's options (s:netrwOPtionsRestore)
1636" - restore a user option when != safe option (s:NetrwRestoreSetting)
1637" vt: (variable type) normally its either "w:" or "s:"
1638fun! s:NetrwOptionsSave(vt)
1639" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1640" 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 +02001641" 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>"))
1642" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001643
1644 if !exists("{a:vt}netrw_optionsave")
1645 let {a:vt}netrw_optionsave= 1
1646 else
1647" call Dret("s:NetrwOptionsSave : options already saved")
1648 return
1649 endif
1650" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1651
1652 " Save current settings and current directory
1653" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1654 let s:yykeep = @@
1655 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1656 let {a:vt}netrw_aikeep = &l:ai
1657 let {a:vt}netrw_awkeep = &l:aw
1658 let {a:vt}netrw_bhkeep = &l:bh
1659 let {a:vt}netrw_blkeep = &l:bl
1660 let {a:vt}netrw_btkeep = &l:bt
1661 let {a:vt}netrw_bombkeep = &l:bomb
1662 let {a:vt}netrw_cedit = &cedit
1663 let {a:vt}netrw_cikeep = &l:ci
1664 let {a:vt}netrw_cinkeep = &l:cin
1665 let {a:vt}netrw_cinokeep = &l:cino
1666 let {a:vt}netrw_comkeep = &l:com
1667 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001668 let {a:vt}netrw_cuckeep = &l:cuc
1669 let {a:vt}netrw_culkeep = &l:cul
1670" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001671 let {a:vt}netrw_diffkeep = &l:diff
1672 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001673 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1674 let {a:vt}netrw_ffkeep = &l:ff
1675 endif
1676 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1677 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001678 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 let {a:vt}netrw_hidkeep = &l:hidden
1680 let {a:vt}netrw_imkeep = &l:im
1681 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001682 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 let {a:vt}netrw_lskeep = &l:ls
1684 let {a:vt}netrw_makeep = &l:ma
1685 let {a:vt}netrw_magickeep = &l:magic
1686 let {a:vt}netrw_modkeep = &l:mod
1687 let {a:vt}netrw_nukeep = &l:nu
1688 let {a:vt}netrw_rnukeep = &l:rnu
1689 let {a:vt}netrw_repkeep = &l:report
1690 let {a:vt}netrw_rokeep = &l:ro
1691 let {a:vt}netrw_selkeep = &l:sel
1692 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693 if !g:netrw_use_noswf
1694 let {a:vt}netrw_swfkeep = &l:swf
1695 endif
1696 let {a:vt}netrw_tskeep = &l:ts
1697 let {a:vt}netrw_twkeep = &l:tw " textwidth
1698 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1699 let {a:vt}netrw_wrapkeep = &l:wrap
1700 let {a:vt}netrw_writekeep = &l:write
1701
1702 " save a few selected netrw-related variables
1703" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1704 if g:netrw_keepdir
1705 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001706" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001707 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001708 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001709 sil! let {a:vt}netrw_starkeep = @*
1710 sil! let {a:vt}netrw_pluskeep = @+
1711 endif
1712 sil! let {a:vt}netrw_slashkeep= @/
1713
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001714" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001715" 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>"))
1716" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1717endfun
1718
1719" ---------------------------------------------------------------------
1720" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1721" Use s:NetrwSaveOptions() to save user settings
1722" Use s:NetrwOptionsRestore() to restore user settings
1723fun! s:NetrwOptionsSafe(islocal)
1724" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1725" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1726" 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>"))
1727 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1728 call s:NetrwSetSafeSetting("&l:ai",0)
1729 call s:NetrwSetSafeSetting("&l:aw",0)
1730 call s:NetrwSetSafeSetting("&l:bl",0)
1731 call s:NetrwSetSafeSetting("&l:bomb",0)
1732 if a:islocal
1733 call s:NetrwSetSafeSetting("&l:bt","nofile")
1734 else
1735 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1736 endif
1737 call s:NetrwSetSafeSetting("&l:ci",0)
1738 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001739 if g:netrw_fastbrowse > a:islocal
1740 call s:NetrwSetSafeSetting("&l:bh","hide")
1741 else
1742 call s:NetrwSetSafeSetting("&l:bh","delete")
1743 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001744 call s:NetrwSetSafeSetting("&l:cino","")
1745 call s:NetrwSetSafeSetting("&l:com","")
1746 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1747 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1748 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001749 if &go =~ 'a' | set go-=a | endif
1750 if &go =~ 'A' | set go-=A | endif
1751 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001752 call s:NetrwSetSafeSetting("&l:hid",0)
1753 call s:NetrwSetSafeSetting("&l:im",0)
1754 setl isk+=@ isk+=* isk+=/
1755 call s:NetrwSetSafeSetting("&l:magic",1)
1756 if g:netrw_use_noswf
1757 call s:NetrwSetSafeSetting("swf",0)
1758 endif
1759 call s:NetrwSetSafeSetting("&l:report",10000)
1760 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1761 call s:NetrwSetSafeSetting("&l:spell",0)
1762 call s:NetrwSetSafeSetting("&l:tw",0)
1763 call s:NetrwSetSafeSetting("&l:wig","")
1764 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001765
1766 " set up cuc and cul based on g:netrw_cursor and listing style
1767 " COMBAK -- cuc cul related
1768 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001769
1770 " allow the user to override safe options
1771" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1772 if &ft == "netrw"
1773" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1774 keepalt NetrwKeepj doau FileType netrw
1775 endif
1776
1777" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1778" 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>"))
1779" call Dret("s:NetrwOptionsSafe")
1780endfun
1781
1782" ---------------------------------------------------------------------
1783" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1784fun! s:NetrwOptionsRestore(vt)
1785" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001786" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001787" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001788 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001789" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001790
1791 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1792 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001793" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001794 filetype detect
1795" 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>"))
1796 else
1797 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001798 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001799" 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 +02001800" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001801 return
1802 endif
1803 unlet {a:vt}netrw_optionsave
1804
1805 if exists("+acd")
1806 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001807" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001808 let curdir = getcwd()
1809 let &l:acd = {a:vt}netrw_acdkeep
1810 unlet {a:vt}netrw_acdkeep
1811 if &l:acd
1812 call s:NetrwLcd(curdir)
1813 endif
1814 endif
1815 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001816" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001817 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1818 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1819 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1820 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1821 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001822" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1824 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1825 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1826 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1827 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001828" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001829 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1830 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1831 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1832 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1833 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001834 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1836 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1837 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001838 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001839 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1840" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1841 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1842 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1843" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1844 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1845" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1847 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001848 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001849 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1850 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1851" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1853 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1854 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1855 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1856" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001857 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1859 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1860 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 call s:NetrwRestoreSetting("s:yykeep","@@")
1864 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1865 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1866 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1867 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1868
Bram Moolenaara6878372014-03-22 21:02:50 +01001869 if exists("{a:vt}netrw_swfkeep")
1870 if &directory == ""
1871 " user hasn't specified a swapfile directory;
1872 " netrw will temporarily set the swapfile directory
1873 " to the current directory as returned by getcwd().
1874 let &l:directory= getcwd()
1875 sil! let &l:swf = {a:vt}netrw_swfkeep
1876 setl directory=
1877 unlet {a:vt}netrw_swfkeep
1878 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001879 if !g:netrw_use_noswf
1880 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1881 sil! let &l:swf= {a:vt}netrw_swfkeep
1882 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001883 unlet {a:vt}netrw_swfkeep
1884 endif
1885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001886 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001887 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1888 if exists("{a:vt}netrw_dirkeep")
1889 call s:NetrwLcd(dirkeep)
1890 unlet {a:vt}netrw_dirkeep
1891 endif
1892 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001893 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001894" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001895 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1896 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001897 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001898 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001899
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001900" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1901" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1902" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1903" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1904" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001905 " Moved the filetype detect here from NetrwGetFile() because remote files
1906 " were having their filetype detect-generated settings overwritten by
1907 " NetrwOptionRestore.
1908 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001909" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1910 filetype detect
1911" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001912 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001913" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001914" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001915" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001916endfun
1917
1918" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001919" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1920" but only when the options' value and the safe setting differ
1921" Doing this means that netrw will not come up as having changed a
1922" setting last when it really didn't actually change it.
1923"
1924" Called from s:NetrwOptionsSafe
1925" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1926fun! s:NetrwSetSafeSetting(setting,safesetting)
1927" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001928
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929 if a:setting =~ '^&'
1930" call Decho("fyi: a:setting starts with &")
1931 exe "let settingval= ".a:setting
1932" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001933
Bram Moolenaar85850f32019-07-19 22:05:51 +02001934 if settingval != a:safesetting
1935" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1936 if type(a:safesetting) == 0
1937 exe "let ".a:setting."=".a:safesetting
1938 elseif type(a:safesetting) == 1
1939 exe "let ".a:setting."= '".a:safesetting."'"
1940 else
1941 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1942 endif
1943 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001944 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001945
Bram Moolenaar85850f32019-07-19 22:05:51 +02001946" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001947endfun
1948
1949" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001950" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1951" but only if the setting value differs from the associated keepvar.
1952" Doing this means that netrw will not come up as having changed a
1953" setting last when it really didn't actually change it.
1954"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001955" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" keepvars are set up by s:NetrwOptionsSave
1957fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001958""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001959
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960 " typically called from s:NetrwOptionsRestore
1961 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1962 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001963 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964 if exists(a:keepvar)
1965 exe "let keepvarval= ".a:keepvar
1966 exe "let setting= ".a:setting
1967
1968"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1969"" call Decho("fyi: keepvarval=".keepvarval)
1970"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1971
1972 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001973"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001974 if type(a:setting) == 0
1975 exe "let ".a:setting."= ".keepvarval
1976 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001977 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001978 else
1979 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1980 endif
1981 endif
1982
1983 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001984 endif
1985
Bram Moolenaar85850f32019-07-19 22:05:51 +02001986"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001987endfun
1988
1989" ---------------------------------------------------------------------
1990" NetrwStatusLine: {{{2
1991fun! NetrwStatusLine()
1992
1993" vvv NetrwStatusLine() debugging vvv
1994" let g:stlmsg=""
1995" if !exists("w:netrw_explore_bufnr")
1996" let g:stlmsg="!X<explore_bufnr>"
1997" elseif w:netrw_explore_bufnr != bufnr("%")
1998" let g:stlmsg="explore_bufnr!=".bufnr("%")
1999" endif
2000" if !exists("w:netrw_explore_line")
2001" let g:stlmsg=" !X<explore_line>"
2002" elseif w:netrw_explore_line != line(".")
2003" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2004" endif
2005" if !exists("w:netrw_explore_list")
2006" let g:stlmsg=" !X<explore_list>"
2007" endif
2008" ^^^ NetrwStatusLine() debugging ^^^
2009
2010 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")
2011 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002012 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002013 let &laststatus = s:netrw_users_ls
2014 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2015 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2016 return ""
2017 else
2018 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2019 endif
2020endfun
2021
Bram Moolenaar85850f32019-07-19 22:05:51 +02002022" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002023" Netrw Transfer Functions: {{{1
2024" ===============================
2025
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002027" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002028" mode: =0 read remote file and insert before current line
2029" =1 read remote file and insert after current line
2030" =2 replace with remote file
2031" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002032fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002033" 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 +00002034
Bram Moolenaar5c736222010-01-06 20:54:52 +01002035 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002036 call s:NetrwOptionsSave("w:")
2037 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002038 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002039 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2040 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2041 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002042" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043
Bram Moolenaar5c736222010-01-06 20:54:52 +01002044 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002046 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002048 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049 elseif a:mode == 2 " replace with remote file
2050 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002051 elseif a:mode == 3 " skip read of file (leave as temporary)
2052 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 else
2054 exe a:mode
2055 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002058" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059
Bram Moolenaar5c736222010-01-06 20:54:52 +01002060 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002061 let tmpfile= s:GetTempfile("")
2062 if tmpfile == ""
2063" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002064 return
2065 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002067 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 " attempt to repeat with previous host-file-etc
2070 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002071" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 let choice = b:netrw_lastfile
2073 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 else
2076 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002077" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002078
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002080 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002081 echomsg 'NetRead Usage:'
2082 echomsg ':Nread machine:path uses rcp'
2083 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2084 echomsg ':Nread "machine id password path" uses ftp'
2085 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2086 echomsg ':Nread fetch://machine/path uses fetch'
2087 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2088 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002089 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002090 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002091 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2092 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2093 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2094 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002095 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002096 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002097
Bram Moolenaar9964e462007-05-05 17:54:07 +00002098 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002099 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002100" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002101 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002102 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002103 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 else
2105 " case "... ... ..."
2106 let choice = strpart(choice,1,strlen(choice)-1)
2107 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002108
Bram Moolenaar9964e462007-05-05 17:54:07 +00002109 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 let wholechoice = wholechoice . " " . choice
2111 let ichoice = ichoice + 1
2112 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002113 if !exists("g:netrw_quiet")
2114 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2115 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002116" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 return
2118 endif
2119 let choice= a:{ichoice}
2120 endwhile
2121 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2122 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 endif
2124 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002126" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002128
Bram Moolenaar5c736222010-01-06 20:54:52 +01002129 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002130 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002131 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002132" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002133 return
2134 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002135 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002136
Bram Moolenaar8d043172014-01-23 14:24:41 +01002137 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002138" 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 +02002139 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002140" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002141 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002142" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002143 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002145
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002146 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002147 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002148 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002149 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2150 echo "(netrw) Processing your read request..."
2151 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002152
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002154 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002156" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002157 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002159 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 " ER: the tmpfile is full path: rcp sees C:\... as host C
2161 if s:netrw_has_nt_rcp == 1
2162 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2163 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2164 else
2165 " Any way needed it machine contains a '.'
2166 let uid_machine = g:netrw_machine .'.'. $USERNAME
2167 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2170 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2171 else
2172 let uid_machine = g:netrw_machine
2173 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002175 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 +00002176 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002178
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002180 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002182" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002183 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002185 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002186 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002189 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002190 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002192 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002193 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002194" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002195 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196 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 +00002197 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 endif
2200 " 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 +00002201 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002202 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002203 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002204 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002205 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002207 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002209 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2210 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002211 q!
2212 endif
2213 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002214 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002216
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002218 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2220 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002222 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002223 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002224 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002225 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002227 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002230 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233
Bram Moolenaar97d62492012-11-15 21:28:22 +01002234 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002235 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002237" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002238 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002239 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002240 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002246 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002247
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002252 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002255 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002258
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 " perform ftp:
2260 " -i : turns off interactive prompting from ftp
2261 " -n unix : DON'T use <.netrc>, even though it exists
2262 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002263 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002264 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2266 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002268 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002269 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002270 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002272 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002273 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002275
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002277 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002281 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 else
2283 let useport= ""
2284 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002285 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2286 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002287 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002288 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2289 else
2290 let tmpfile_get = tmpfile
2291 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002292 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 +00002293 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002294 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002295
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002296 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002297 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002298 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002299" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002300 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002301 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002302 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002303 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002304" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002305 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002307
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002308 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2309 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002310" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002311 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312 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 +00002313 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314 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 +00002315 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002316 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002317
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002318 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002319 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002321 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2322 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2324" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2325 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 +00002326 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002328 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002329 endif
2330 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002332 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002333
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002334 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002335 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002336 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002338
Bram Moolenaar5c736222010-01-06 20:54:52 +01002339 if !executable(g:netrw_dav_cmd)
2340 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2341" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2342 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002345 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 +01002346 else
2347 " Construct execution string (four lines) which will be passed through filter
2348 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2349 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002350 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002351 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002352 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002354 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002356 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002357 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002358 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002359 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2360 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002361
Bram Moolenaar5c736222010-01-06 20:54:52 +01002362 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002363 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002365 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002367 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002369
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002370 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002371 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002372 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002373" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002374 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 +00002375 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002377
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002381 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002382" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002384 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002385 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002386 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002387" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002388 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002390 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 let netrw_option= "http"
2392 else
2393 let netrw_option= "ftp"
2394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002396
Bram Moolenaar446cb832008-06-24 21:56:24 +00002397 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002398 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 +00002399 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002400 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 +00002401 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002402
Bram Moolenaar446cb832008-06-24 21:56:24 +00002403 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002406 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002407
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002409 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002410 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2412 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 +00002413 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002417 " NetRead: (file) NetRead Method #10 {{{3
2418 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002419" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2420 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002421 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2422 let b:netrw_lastfile = choice
2423
2424 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002425 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002426 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002427 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002428 endif
2429 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002430
Bram Moolenaar5c736222010-01-06 20:54:52 +01002431 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002433" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002435 unlet b:netrw_fname
2436 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002437 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 +01002438" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002439 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002441 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002442
Bram Moolenaar9964e462007-05-05 17:54:07 +00002443" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444endfun
2445
2446" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002447" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002448fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002449" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002450
Bram Moolenaar5c736222010-01-06 20:54:52 +01002451 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002453 call s:NetrwOptionsSave("w:")
2454 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002455
Bram Moolenaar5c736222010-01-06 20:54:52 +01002456 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002457 let tmpfile= s:GetTempfile("")
2458 if tmpfile == ""
2459" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002460 return
2461 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002462
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 if a:0 == 0
2464 let ichoice = 0
2465 else
2466 let ichoice = 1
2467 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaar9964e462007-05-05 17:54:07 +00002469 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002470" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002471 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002472 " For binary writes, always write entire file.
2473 " (line numbers don't really make sense for that).
2474 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002475" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002476 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002477 elseif g:netrw_cygwin
2478 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002479 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" 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 +01002481 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002482 else
2483 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" 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 +01002485 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002486 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002487
Bram Moolenaar9964e462007-05-05 17:54:07 +00002488 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002489 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002490 " on the temporary file's name. Deletion of the temporary file during
2491 " cleanup then causes an error message.
2492 0file!
2493 endif
2494
Bram Moolenaar5c736222010-01-06 20:54:52 +01002495 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002496 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002497
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002499 " attempt to repeat with previous host-file-etc
2500 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002501" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 let choice = b:netrw_lastfile
2503 let ichoice= ichoice + 1
2504 else
2505 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002506
Bram Moolenaar8d043172014-01-23 14:24:41 +01002507 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002509 echomsg 'NetWrite Usage:"'
2510 echomsg ':Nwrite machine:path uses rcp'
2511 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2512 echomsg ':Nwrite "machine id password path" uses ftp'
2513 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2514 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2515 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2516 echomsg ':Nwrite rcp://machine/path uses rcp'
2517 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2518 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2519 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002520 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002522
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002523 elseif match(choice,"^\"") != -1
2524 if match(choice,"\"$") != -1
2525 " case "..."
2526 let choice=strpart(choice,1,strlen(choice)-2)
2527 else
2528 " case "... ... ..."
2529 let choice = strpart(choice,1,strlen(choice)-1)
2530 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002531
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002532 while match(choice,"\"$") == -1
2533 let wholechoice= wholechoice . " " . choice
2534 let ichoice = ichoice + 1
2535 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002536 if !exists("g:netrw_quiet")
2537 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2538 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002539" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 return
2541 endif
2542 let choice= a:{ichoice}
2543 endwhile
2544 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2545 endif
2546 endif
2547 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002548 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002549" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002550
Bram Moolenaar9964e462007-05-05 17:54:07 +00002551 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002552 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002553 if !exists("b:netrw_method") || b:netrw_method < 0
2554" call Dfunc("netrw#NetWrite : unsupported method")
2555 return
2556 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002557
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002558 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002559 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002560 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002561 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2562 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002563" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002564 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002565
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002566 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002568 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002569" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002570 if s:netrw_has_nt_rcp == 1
2571 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2572 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2573 else
2574 let uid_machine = g:netrw_machine .'.'. $USERNAME
2575 endif
2576 else
2577 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2578 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2579 else
2580 let uid_machine = g:netrw_machine
2581 endif
2582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002583 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 +00002584 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002585
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002586 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002587 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002588 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002590 let netrw_fname = b:netrw_fname
2591
2592 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2593 let bhkeep = &l:bh
2594 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002595 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002599 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002600 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002602 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002603 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002605 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002606 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609 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 +00002610 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2612 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 endif
2614 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2615 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002616 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002617 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002618 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002619 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002621
2622 " remove enew buffer (quietly)
2623 let filtbuf= bufnr("%")
2624 exe curbuf."b!"
2625 let &l:bh = bhkeep
2626 exe filtbuf."bw!"
2627
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002629
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002632 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002633 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002634" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002635 let netrw_fname = b:netrw_fname
2636 let bhkeep = &l:bh
2637
2638 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2639 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002640 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002641 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002642 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002644 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002645 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002648 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002649" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002651 if exists("g:netrw_uid") && g:netrw_uid != ""
2652 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002655 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002656 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002657 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002660 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002661" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002669 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 " save choice/id/password for future use
2673 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002674
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002675 " perform ftp:
2676 " -i : turns off interactive prompting from ftp
2677 " -n unix : DON'T use <.netrc>, even though it exists
2678 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002679 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002681 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2682 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002683 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002684 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002685 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 let mod=1
2687 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002688
2689 " remove enew buffer (quietly)
2690 let filtbuf= bufnr("%")
2691 exe curbuf."b!"
2692 let &l:bh= bhkeep
2693 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002694
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002695 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002696 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002697 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002698" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002700 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 else
2702 let useport= ""
2703 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704 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 +00002705 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002706
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002707 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002708 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002710" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002711 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2712 if executable(curl)
2713 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714 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 +01002715 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002716 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002717 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002718
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002719 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002720 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002721 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002722" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002723
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002724 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002725 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2726 let bhkeep = &l:bh
2727
2728 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2729 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002730 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002731 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002732
Bram Moolenaarff034192013-04-24 18:51:19 +02002733 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002735 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002737 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002738 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002739 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002740 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002741 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002742 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002743
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002745 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002747
2748 " remove enew buffer (quietly)
2749 let filtbuf= bufnr("%")
2750 exe curbuf."b!"
2751 let &l:bh = bhkeep
2752 exe filtbuf."bw!"
2753
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002754 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002755
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002756 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002757 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002758 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002759" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002760 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 +00002761 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002762
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002763 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002764 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002765 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002766" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002767 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2769 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2770 else
2771 let uid_machine = g:netrw_machine
2772 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002773
2774 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2775 let bhkeep = &l:bh
2776 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002777 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002778 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002779
Bram Moolenaarff034192013-04-24 18:51:19 +02002780 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002783 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002784 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002785 let filtbuf= bufnr("%")
2786 exe curbuf."b!"
2787 let &l:bh = bhkeep
2788 exe filtbuf."bw!"
2789 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002790
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002791 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002793 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002794 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002795 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002797 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002798
Bram Moolenaar5c736222010-01-06 20:54:52 +01002799 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002800" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002802" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002803 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002805 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002806
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002807 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002809 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" 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 +02002811 elseif !exists("leavemod")
2812 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002814 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002817
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002819endfun
2820
2821" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002822" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002823" uses NetRead to get a copy of the file into a temporarily file,
2824" then sources that file,
2825" then removes that file.
2826fun! netrw#NetSource(...)
2827" call Dfunc("netrw#NetSource() a:0=".a:0)
2828 if a:0 > 0 && a:1 == '?'
2829 " give help
2830 echomsg 'NetSource Usage:'
2831 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2832 echomsg ':Nsource fetch://machine/path uses fetch'
2833 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002834 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002835 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2836 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2837 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2838 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2839 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002840 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002841 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002842 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002844" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002847 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002849 if delete(s:netrw_tmpfile)
2850 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2851 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 unlet s:netrw_tmpfile
2853 else
2854 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2855 endif
2856 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002857 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 endif
2859" call Dret("netrw#NetSource")
2860endfun
2861
Bram Moolenaar8d043172014-01-23 14:24:41 +01002862" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002863" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2864" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002865fun! netrw#SetTreetop(iscmd,...)
2866" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2867" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002868
Bram Moolenaar85850f32019-07-19 22:05:51 +02002869 " iscmd==0: netrw#SetTreetop called using gn mapping
2870 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2871" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002872 " clear out the current tree
2873 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002874" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002875 let inittreetop= w:netrw_treetop
2876 unlet w:netrw_treetop
2877 endif
2878 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002879" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002880 unlet w:netrw_treedict
2881 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002883
Bram Moolenaar85850f32019-07-19 22:05:51 +02002884 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002885 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002886" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002887 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888 if isdirectory(s:NetrwFile(a:1))
2889" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002890 let treedir = a:1
2891 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002893 let treedir = b:netrw_curdir."/".a:1
2894 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002896 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897 " normally the cursor is left in the message window.
2898 " However, here this results in the directory being listed in the message window, which is not wanted.
2899 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002900 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002902 let treedir = "."
2903 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002904 endif
2905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002907
2908 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909 let islocal= expand("%") !~ '^\a\{3,}://'
2910" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002911
2912 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002913 if islocal
2914 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2915 else
2916 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2917 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002918
Bram Moolenaara6878372014-03-22 21:02:50 +01002919" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002920endfun
2921
Bram Moolenaar9964e462007-05-05 17:54:07 +00002922" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002923" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924" readcmd == %r : replace buffer with newly read file
2925" == 0r : read file at top of buffer
2926" == r : read file after current line
2927" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002928fun! s:NetrwGetFile(readcmd, tfile, method)
2929" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002930
2931 " readcmd=='t': simply do nothing
2932 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002933" 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 +01002934" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002935 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002936 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002937
Bram Moolenaar9964e462007-05-05 17:54:07 +00002938 " get name of remote filename (ie. url and all)
2939 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002940" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002941
Bram Moolenaar9964e462007-05-05 17:54:07 +00002942 if exists("*NetReadFixup")
2943 " for the use of NetReadFixup (not otherwise used internally)
2944 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002945 endif
2946
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947 if a:readcmd[0] == '%'
2948 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002949" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002950
2951 " rename the current buffer to the temp file (ie. tfile)
2952 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002953 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002954 else
2955 let tfile= a:tfile
2956 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002957 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958
2959 " edit temporary file (ie. read the temporary file in)
2960 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002961" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962 call zip#Browse(tfile)
2963 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002964" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002966 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002969 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002972 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 call tar#Browse(tfile)
2975 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002980 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 endif
2982
2983 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002984 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002985
Bram Moolenaar71badf92023-04-22 22:40:14 +01002986 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002987 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002988 " Note that isk must not include a "/" for scripts.vim
2989 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002990" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2991" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002992" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002993" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2994 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002995 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996 filetype detect
2997" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002998 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002999" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003000 let line1 = 1
3001 let line2 = line("$")
3002
Bram Moolenaar8d043172014-01-23 14:24:41 +01003003 elseif !&ma
3004 " 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 +01003005 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003006" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003007 return
3008
Bram Moolenaar9964e462007-05-05 17:54:07 +00003009 elseif s:FileReadable(a:tfile)
3010 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003012 let curline = line(".")
3013 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003014" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003015 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003016 let line1= curline + 1
3017 let line2= line("$") - lastline + 1
3018
3019 else
3020 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003021" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3022" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003023 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003024" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 return
3026 endif
3027
3028 " User-provided (ie. optional) fix-it-up command
3029 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003030" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003031 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003032" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003033" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003034 endif
3035
Bram Moolenaaradc21822011-04-01 18:03:16 +02003036 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003037 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003038 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003039 endif
3040
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003041" 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 +00003042
3043 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003044" redraw!
3045
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" 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 +00003047" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003048endfun
3049
Bram Moolenaar9964e462007-05-05 17:54:07 +00003050" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003051" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003052" Input:
3053" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3054" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" b:netrw_method= 1: rcp
3056" 2: ftp + <.netrc>
3057" 3: ftp + machine, id, password, and [path]filename
3058" 4: scp
3059" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003060" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003061" 7: rsync
3062" 8: fetch
3063" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003064" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065" g:netrw_machine= hostname
3066" b:netrw_fname = filename
3067" g:netrw_port = optional port number (for ftp)
3068" g:netrw_choice = copy of input url (choice)
3069fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003070" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003071
Bram Moolenaar251e1912011-06-19 05:09:16 +02003072 " sanity check: choice should have at least three slashes in it
3073 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3074 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3075 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003076" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003077 return
3078 endif
3079
Bram Moolenaar5c736222010-01-06 20:54:52 +01003080 " record current g:netrw_machine, if any
3081 " curmachine used if protocol == ftp and no .netrc
3082 if exists("g:netrw_machine")
3083 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003084" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003085 else
3086 let curmachine= "N O T A HOST"
3087 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003088 if exists("g:netrw_port")
3089 let netrw_port= g:netrw_port
3090 endif
3091
3092 " insure that netrw_ftp_cmd starts off every method determination
3093 " with the current g:netrw_ftp_cmd
3094 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003095
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003096 " initialization
3097 let b:netrw_method = 0
3098 let g:netrw_machine = ""
3099 let b:netrw_fname = ""
3100 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003101 let g:netrw_choice = a:choice
3102
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003104 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003105 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3106 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003107 " rcpurm : rcp://[user@]host/filename Use rcp
3108 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003110 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003111 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 " rsyncurm : rsync://host[:port]/path Use rsync
3113 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3114 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003115 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3117 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003118 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3119 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003121 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003122 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003123 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003125 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003127 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003128
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003129" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003131 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003134 let b:netrw_method = 1
3135 let userid = substitute(a:choice,rcpurm,'\1',"")
3136 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3137 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 if userid != ""
3139 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003141
Bram Moolenaaradc21822011-04-01 18:03:16 +02003142 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003144" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003145 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003146 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3147 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3148 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003149
Bram Moolenaar15146672011-10-20 22:22:38 +02003150 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003152" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 let b:netrw_method = 5
3154 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3155 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003156 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003157
Bram Moolenaaradc21822011-04-01 18:03:16 +02003158 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003159 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003160" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003162 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003163 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3164 else
3165 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3166 endif
3167 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003168
Bram Moolenaaradc21822011-04-01 18:03:16 +02003169 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 let b:netrw_method = 7
3173 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3174 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003175
Bram Moolenaaradc21822011-04-01 18:03:16 +02003176 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003178" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003179 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3181 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3182 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003183" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 if userid != ""
3185 let g:netrw_uid= userid
3186 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003187
Bram Moolenaaradc21822011-04-01 18:03:16 +02003188 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003189 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003190 call NetUserPass("ftp:".g:netrw_machine)
3191 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003192 " if there's a change in hostname, require password re-entry
3193 unlet s:netrw_passwd
3194 endif
3195 if exists("netrw_port")
3196 unlet netrw_port
3197 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003198 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003199
Bram Moolenaar446cb832008-06-24 21:56:24 +00003200 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003201 let b:netrw_method = 3
3202 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003203 let host= substitute(g:netrw_machine,'\..*$','','')
3204 if exists("s:netrw_hup[host]")
3205 call NetUserPass("ftp:".host)
3206
Nir Lichtman1e34b952024-05-08 19:19:34 +02003207 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003208" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3209" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003210 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003211 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003212" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003213 endif
3214 let b:netrw_method= 2
3215 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003216" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003217 let b:netrw_method= 2
3218 else
3219 if !exists("g:netrw_uid") || g:netrw_uid == ""
3220 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003221 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003222 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003223 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003224 endif
3225 let b:netrw_method= 3
3226 endif
3227 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003228
Bram Moolenaaradc21822011-04-01 18:03:16 +02003229 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003231" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 let b:netrw_method = 8
3233 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3234 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3235 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3236 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003237
Bram Moolenaaradc21822011-04-01 18:03:16 +02003238 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003239 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003240" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3243 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003244 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003246 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003247
Bram Moolenaaradc21822011-04-01 18:03:16 +02003248 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003250" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003251 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 let b:netrw_method = 3
3253 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3254 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003255
Bram Moolenaar9964e462007-05-05 17:54:07 +00003256 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 let b:netrw_method = 2
3258 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3259 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3260 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003261
Bram Moolenaaradc21822011-04-01 18:03:16 +02003262 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003263 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003264" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 let b:netrw_method = 9
3266 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3267 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003268
Bram Moolenaaradc21822011-04-01 18:03:16 +02003269 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003271" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003272 let b:netrw_method = 1
3273 let userid = substitute(a:choice,rcphf,'\2',"")
3274 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3275 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003276" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3277" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3278" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3279" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003280 if userid != ""
3281 let g:netrw_uid= userid
3282 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003283
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003284 " Method#10: file://user@hostname/...path-to-file {{{3
3285 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003287 let b:netrw_method = 10
3288 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003289" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003290
Bram Moolenaaradc21822011-04-01 18:03:16 +02003291 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003292 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003293 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003294 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003295 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003296 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003298 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003299
Bram Moolenaar81695252004-12-29 20:58:21 +00003300 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003301 " remove any leading [:#] from port number
3302 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3303 elseif exists("netrw_port")
3304 " retain port number as implicit for subsequent ftp operations
3305 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003306 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003307
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003308" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3309" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3310" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3311" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003312" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003313" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003314" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003315" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003316" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003317" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003319" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321
Bram Moolenaar9964e462007-05-05 17:54:07 +00003322" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003323" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003324" Usage: :call NetUserPass() -- will prompt for userid and password
3325" :call NetUserPass("uid") -- will prompt for password
3326" :call NetUserPass("uid","password") -- sets global userid and password
3327" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3328" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329fun! NetUserPass(...)
3330
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003331" call Dfunc("NetUserPass() a:0=".a:0)
3332
3333 if !exists('s:netrw_hup')
3334 let s:netrw_hup= {}
3335 endif
3336
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003338 " case: no input arguments
3339
3340 " change host and username if not previously entered; get new password
3341 if !exists("g:netrw_machine")
3342 let g:netrw_machine= input('Enter hostname: ')
3343 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346 let g:netrw_uid= input('Enter username: ')
3347 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003349 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003350
3351 " set up hup database
3352 let host = substitute(g:netrw_machine,'\..*$','','')
3353 if !exists('s:netrw_hup[host]')
3354 let s:netrw_hup[host]= {}
3355 endif
3356 let s:netrw_hup[host].uid = g:netrw_uid
3357 let s:netrw_hup[host].passwd = s:netrw_passwd
3358
3359 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003360 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003361
3362 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003363 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003364 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003365" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003366 let host = substitute(a:1,'^ftp:','','')
3367 let host = substitute(host,'\..*','','')
3368 if exists("s:netrw_hup[host]")
3369 let g:netrw_uid = s:netrw_hup[host].uid
3370 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003371" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3372" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003373 else
3374 let g:netrw_uid = input("Enter UserId: ")
3375 let s:netrw_passwd = inputsecret("Enter Password: ")
3376 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003377
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003378 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003379 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003380" 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 +02003381 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003382 if g:netrw_machine =~ '[0-9.]\+'
3383 let host= g:netrw_machine
3384 else
3385 let host= substitute(g:netrw_machine,'\..*$','','')
3386 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387 else
3388 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003389 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003391" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003392 if exists("g:netrw_passwd")
3393 " ask for password if one not previously entered
3394 let s:netrw_passwd= g:netrw_passwd
3395 else
3396 let s:netrw_passwd = inputsecret("Enter Password: ")
3397 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003398 endif
3399
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003400" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003401 if exists("host")
3402 if !exists('s:netrw_hup[host]')
3403 let s:netrw_hup[host]= {}
3404 endif
3405 let s:netrw_hup[host].uid = g:netrw_uid
3406 let s:netrw_hup[host].passwd = s:netrw_passwd
3407 endif
3408
3409 elseif a:0 == 2
3410 let g:netrw_uid = a:1
3411 let s:netrw_passwd = a:2
3412
3413 elseif a:0 == 3
3414 " enter hostname, user-id, and password into the hup dictionary
3415 let host = substitute(a:1,'^\a\+:','','')
3416 let host = substitute(host,'\..*$','','')
3417 if !exists('s:netrw_hup[host]')
3418 let s:netrw_hup[host]= {}
3419 endif
3420 let s:netrw_hup[host].uid = a:2
3421 let s:netrw_hup[host].passwd = a:3
3422 let g:netrw_uid = s:netrw_hup[host].uid
3423 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003424" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3425" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003427
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003428" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430
Bram Moolenaar85850f32019-07-19 22:05:51 +02003431" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003432" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003433" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003435" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003436" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3437fun! s:ExplorePatHls(pattern)
3438" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3439 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003441 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003442" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003443 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3444" call Dret("s:ExplorePatHls repat<".repat.">")
3445 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003446endfun
3447
3448" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003449" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003450" 0: (user: <mb>) bookmark current directory
3451" 1: (user: <gb>) change to the bookmarked directory
3452" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003453" 3: (browsing) records current directory history
3454" 4: (user: <u>) go up (previous) directory, using history
3455" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003456" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003457fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003458" 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 +02003459 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3460" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3461 return
3462 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003463
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003464 let ykeep = @@
3465 let curbufnr = bufnr("%")
3466
Bram Moolenaar9964e462007-05-05 17:54:07 +00003467 if a:chg == 0
3468 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003469" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003470 if exists("s:netrwmarkfilelist_{curbufnr}")
3471 call s:NetrwBookmark(0)
3472 echo "bookmarked marked files"
3473 else
3474 call s:MakeBookmark(a:curdir)
3475 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003476 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003477
KSR-Yasudaf4498252023-10-06 03:34:17 +09003478 try
3479 call s:NetrwBookHistSave()
3480 catch
3481 endtry
3482
Bram Moolenaar9964e462007-05-05 17:54:07 +00003483 elseif a:chg == 1
3484 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003485" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003486 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003487" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003488 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489 else
3490 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3491 endif
3492
3493 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003494" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003495 let didwork= 0
3496 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003497" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003498 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003499" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003500 let cnt= 1
3501 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003503 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 let didwork = 1
3505 let cnt = cnt + 1
3506 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003507 endif
3508
3509 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003510 " Note: history is saved only when PerformListing is done;
3511 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3512 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 let first = 1
3514 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003515 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003516 while ( first || cnt != g:netrw_dirhistcnt )
3517" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003518 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003519" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003520 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 let didwork= 1
3522 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003523 let histcnt = histcnt + 1
3524 let first = 0
3525 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 if cnt < 0
3527 let cnt= cnt + g:netrw_dirhistmax
3528 endif
3529 endwhile
3530 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003531 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003532 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003533 if didwork
3534 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3535 endif
3536
3537 elseif a:chg == 3
3538 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003539" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003540 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 +02003541 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003542 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3543 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003545" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003546 endif
3547
3548 elseif a:chg == 4
3549 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003550" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3553 if g:netrw_dirhistcnt < 0
3554 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 endif
3556 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003557 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003558 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3560" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003561 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003562 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003563" call Decho("setl ma noro",'~'.expand("<slnum>"))
3564 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003565 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003566" call Decho("setl nomod",'~'.expand("<slnum>"))
3567" 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 +00003568 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003569" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3570 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003571 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003572 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003573 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003576 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003577 echo "Sorry, no predecessor directory exists yet"
3578 endif
3579
3580 elseif a:chg == 5
3581 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003582" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003583 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3585 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3586" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003588" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003589 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003590 sil! NetrwKeepj %d _
3591" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3592" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003593 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003594" 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 +02003595 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003596" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3597 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003598 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003599 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3600 if g:netrw_dirhistcnt < 0
3601 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003602 endif
3603 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003604 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003605 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003607 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003608 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003609
3610 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003611" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003612 if exists("s:netrwmarkfilelist_{curbufnr}")
3613 call s:NetrwBookmark(1)
3614 echo "removed marked files from bookmarks"
3615 else
3616 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003617 let iremove = v:count
3618 let dremove = g:netrw_bookmarklist[iremove - 1]
3619" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003620 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003621" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3622 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3623 echo "removed ".dremove." from g:netrw_bookmarklist"
3624" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003625 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003626" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003627
3628 try
3629 call s:NetrwBookHistSave()
3630 catch
3631 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003632 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003633 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003634 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003635 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003636" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003637endfun
3638
3639" ---------------------------------------------------------------------
3640" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003641" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642" Sister function: s:NetrwBookHistSave()
3643fun! s:NetrwBookHistRead()
3644" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003645 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003646" 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 +02003647 return
3648 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003649 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650
3651 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003652 if !exists("s:netrw_initbookhist")
3653 let home = s:NetrwHome()
3654 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003655 if filereadable(s:NetrwFile(savefile))
3656" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003657 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003658 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003659
3660 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003661 if g:netrw_dirhistmax > 0
3662 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003663 if filereadable(s:NetrwFile(savefile))
3664" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003665 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003666 endif
3667 let s:netrw_initbookhist= 1
3668 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003669 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003670 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003671
Bram Moolenaar97d62492012-11-15 21:28:22 +01003672 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003673" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3674" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003675" call Dret("s:NetrwBookHistRead")
3676endfun
3677
3678" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003679" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680" Sister function: s:NetrwBookHistRead()
3681" I used to do this via viminfo but that appears to
3682" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003683" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3684" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003685" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003687" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003688 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003690 return
3691 endif
3692
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003696
3697 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003700 if g:netrw_use_noswf
3701 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3702 else
3703 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3704 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003705 setl nocin noai noci magic nospell nohid wig= noaw
3706 setl ma noro write
3707 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003708 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003709
Bram Moolenaar85850f32019-07-19 22:05:51 +02003710 " rename enew'd file: .netrwhist -- no attempt to merge
3711 " record dirhistmax and current dirhistcnt
3712 " save history
3713" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003714 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3717 if g:netrw_dirhistmax > 0
3718 let lastline = line("$")
3719 let cnt = g:netrw_dirhistcnt
3720 let first = 1
3721 while ( first || cnt != g:netrw_dirhistcnt )
3722 let lastline= lastline + 1
3723 if exists("g:netrw_dirhist_{cnt}")
3724 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3725" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3726 endif
3727 let first = 0
3728 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3729 if cnt < 0
3730 let cnt= cnt + g:netrw_dirhistmax
3731 endif
3732 endwhile
3733 exe "sil! w! ".savefile
3734" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3735 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003736
Bram Moolenaar85850f32019-07-19 22:05:51 +02003737 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003738 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003739 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003740" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 " merge and write .netrwbook
3742 let savefile= s:NetrwHome()."/.netrwbook"
3743
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003744 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003745 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003746 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 for bdm in booklist
3748 if index(g:netrw_bookmarklist,bdm) == -1
3749 call add(g:netrw_bookmarklist,bdm)
3750 endif
3751 endfor
3752 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003753 endif
3754
3755 " construct and save .netrwbook
3756 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003757 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003758" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003760
3761 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762 let bgone= bufnr("%")
3763 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003764 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765
3766" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003767endfun
3768
3769" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003770" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3771" list of the contents of a local or remote directory. It is assumed that the
3772" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3773" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003774" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775fun! s:NetrwBrowse(islocal,dirname)
3776 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003777" 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 +02003778" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3779" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3780" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003781
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003782 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3783 " This is useful when one edits a local file, then :e ., then :Rex
3784 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3785 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003786" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003787 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003788
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003789 " s:NetrwBrowse : initialize history {{{3
3790 if !exists("s:netrw_initbookhist")
3791 NetrwKeepj call s:NetrwBookHistRead()
3792 endif
3793
3794 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003795 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003796 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003797" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003798 else
3799 let dirname= a:dirname
3800 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801
Bram Moolenaar85850f32019-07-19 22:05:51 +02003802 " repoint t:netrw_lexbufnr if appropriate
3803 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3804" call Decho("set repointlexbufnr to true!")
3805 let repointlexbufnr= 1
3806 endif
3807
3808 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003809 if exists("s:netrw_skipbrowse")
3810 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003811" 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 +01003812" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003813 return
3814 endif
3815 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003816 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817" call Dret("s:NetrwBrowse : missing shellescape()")
3818 return
3819 endif
3820 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003821 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822" call Dret("s:NetrwBrowse : missing fnameescape()")
3823 return
3824 endif
3825
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003827 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003828
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003830 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3831 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3832" call Decho("clearing marked files",'~'.expand("<slnum>"))
3833 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3834 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835 endif
3836
3837 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003838 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003839" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3840" 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 +02003841 if s:NetrwLcd(dirname)
3842" call Dret("s:NetrwBrowse : lcd failure")
3843 return
3844 endif
3845 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003846" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003847
Bram Moolenaar5c736222010-01-06 20:54:52 +01003848 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003849 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003850" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003853 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003854 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857
3858 " remove any filetype indicator from end of dirname, except for the
3859 " "this is a directory" indicator (/).
3860 " There shouldn't be one of those here, anyway.
3861 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003862" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 call s:RemotePathAnalysis(dirname)
3864
3865 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3866 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003867 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870 let b:netrw_curdir = dirname
3871 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003872 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3874 sil call netrw#NetRead(2,url)
3875 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003876" call Decho("url<".url.">",'~'.expand("<slnum>"))
3877" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3878" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879 if s:path =~ '.bz2'
3880 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3881 elseif s:path =~ '.gz'
3882 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3883 elseif s:path =~ '.gz'
3884 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3885 else
3886 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3887 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003888 endif
3889
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003890 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003891 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003892 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003893" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895" 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 +00003896
Bram Moolenaar446cb832008-06-24 21:56:24 +00003897" call Dret("s:NetrwBrowse : file<".s:fname.">")
3898 return
3899 endif
3900
Bram Moolenaaradc21822011-04-01 18:03:16 +02003901 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003902 call s:UseBufWinVars()
3903
3904 " set up some variables {{{3
3905 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003906 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907 let s:last_sort_by = g:netrw_sort_by
3908
3909 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003910 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003911
Bram Moolenaar97d62492012-11-15 21:28:22 +01003912 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003913" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003914 let svpos = winsaveview()
3915" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003917
Bram Moolenaar446cb832008-06-24 21:56:24 +00003918 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003919 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3920 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3921" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3922" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3923 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3924 else
3925" " call Decho("2match none",'~'.expand("<slnum>"))
3926 2match none
3927 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003929 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003930 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003931" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003932 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003933" 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 +01003934" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003935 return
3936 endif
3937
3938 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003940 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003941 if b:netrw_curdir =~ '[/\\]$'
3942 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3943 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003944 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003945 let b:netrw_curdir= b:netrw_curdir."/"
3946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 if b:netrw_curdir == ''
3948 if has("amiga")
3949 " On the Amiga, the empty string connotes the current directory
3950 let b:netrw_curdir= getcwd()
3951 else
3952 " under unix, when the root directory is encountered, the result
3953 " from the preceding substitute is an empty string.
3954 let b:netrw_curdir= '/'
3955 endif
3956 endif
3957 if !a:islocal && b:netrw_curdir !~ '/$'
3958 let b:netrw_curdir= b:netrw_curdir.'/'
3959 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003960" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961
3962 " ------------
3963 " (local only) {{{3
3964 " ------------
3965 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003966" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003967
3968 " Set up ShellCmdPost handling. Append current buffer to browselist
3969 call s:LocalFastBrowser()
3970
3971 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3972 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3974" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003976 if s:NetrwLcd(b:netrw_curdir)
3977" call Dret("s:NetrwBrowse : lcd failure")
3978 return
3979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980 endif
3981 endif
3982
3983 " --------------------------------
3984 " remote handling: {{{3
3985 " --------------------------------
3986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988
Bram Moolenaar97d62492012-11-15 21:28:22 +01003989 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003990" 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 +02003991 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003993" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3995 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3996 if dirname !~ '/$'
3997 let dirname= dirname.'/'
3998 endif
3999 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004002 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 endif
4005
4006 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4007 if dirname !~ dirpat
4008 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004009 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004011 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004012" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004013 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004014" 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 +00004015" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4016 return
4017 endif
4018 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004020 endif " (additional remote handling)
4021
Bram Moolenaar85850f32019-07-19 22:05:51 +02004022 " -------------------------------
4023 " Perform Directory Listing: {{{3
4024 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004025 NetrwKeepj call s:NetrwMaps(a:islocal)
4026 NetrwKeepj call s:NetrwCommands(a:islocal)
4027 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004028
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004029 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004030 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004031" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4032
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033 " If there is a rexposn: restore position with rexposn
4034 " Otherwise : set rexposn
4035 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004036" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4037 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4038 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4039 NetrwKeepj exe w:netrw_bannercnt
4040 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004041 else
4042 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4043 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004044 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004045 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004047 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004048 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004049
Bram Moolenaar85850f32019-07-19 22:05:51 +02004050 " repoint t:netrw_lexbufnr if appropriate
4051 if exists("repointlexbufnr")
4052 let t:netrw_lexbufnr= bufnr("%")
4053" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4054 endif
4055
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004056 " restore position
4057 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004058" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4059 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004060 endif
4061
Bram Moolenaara6878372014-03-22 21:02:50 +01004062 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004063 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4064 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004065" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4066" 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 +02004067" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004068 return
4069endfun
4070
4071" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4073" may not apply correctly; ie. netrw's idea of the current directory may
4074" differ from vim's. This function insures that netrw's idea of the current
4075" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004077fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004078" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4079" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4080" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4081" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4082" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004083
4084 " clean up any leading treedepthstring
4085 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4086 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004087" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004088 else
4089 let fname= a:fname
4090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004091
4092 if g:netrw_keepdir
4093 " vim's idea of the current directory possibly may differ from netrw's
4094 if !exists("b:netrw_curdir")
4095 let b:netrw_curdir= getcwd()
4096 endif
4097
Nir Lichtman1e34b952024-05-08 19:19:34 +02004098 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004099 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004100 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004102" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004103 else
4104 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004105 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004106" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107 endif
4108
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004111 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004112" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 else
4114 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 endif
4118 else
4119 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004120 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004121" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4122" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4123" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 endif
4125
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127 return ret
4128endfun
4129
4130" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004131" s:NetrwFileInfo: supports qf (query for file information) {{{2
4132fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004133" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004134 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004136 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004137 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004138 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004139 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004140 let lsopt= "-lsadh --si"
4141 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004142" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004143 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004144
4145 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004147" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004148
Bram Moolenaara6878372014-03-22 21:02:50 +01004149 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004151" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004152
4153 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004156
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004161 endif
4162 else
4163 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4165 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 let fname= substitute(a:fname,".$","","")
4167 else
4168 let fname= a:fname
4169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170 let t = getftime(s:NetrwFile(fname))
4171 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004172 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004173 let sz= s:NetrwHumanReadable(sz)
4174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004175 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4176" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004177 endif
4178 else
4179 echo "sorry, \"qf\" not supported yet for remote files"
4180 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004181 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004182" call Dret("s:NetrwFileInfo")
4183endfun
4184
4185" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004186" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4187fun! s:NetrwFullPath(filename)
4188" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4189 let filename= a:filename
4190 if filename !~ '^/'
4191 let filename= resolve(getcwd().'/'.filename)
4192 endif
4193 if filename != "/" && filename =~ '/$'
4194 let filename= substitute(filename,'/$','','')
4195 endif
4196" " call Dret("s:NetrwFullPath <".filename.">")
4197 return filename
4198endfun
4199
4200" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004201" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004202" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004203" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004204" 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 +00004205fun! s:NetrwGetBuffer(islocal,dirname)
4206" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004207" 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 +02004208" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4209" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004210 let dirname= a:dirname
4211
4212 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004213" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004214 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004215" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004216 let s:netrwbuf= {}
4217 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004218" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4219" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4220
4221 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4222 let bufnum = -1
4223
4224 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4225 if has_key(s:netrwbuf,"NetrwTreeListing")
4226 let bufnum= s:netrwbuf["NetrwTreeListing"]
4227 else
4228 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4229 endif
4230" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4231 if !bufexists(bufnum)
4232 call remove(s:netrwbuf,"NetrwTreeListing"])
4233 let bufnum= -1
4234 endif
4235 elseif bufnr("NetrwTreeListing") != -1
4236 let bufnum= bufnr("NetrwTreeListing")
4237" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4238 else
4239" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4240 let bufnum= -1
4241 endif
4242
4243 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004244 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004245" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004246 if !bufexists(bufnum)
4247 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4248 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004249 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004250
Bram Moolenaar446cb832008-06-24 21:56:24 +00004251 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004252" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004253 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4256
Bram Moolenaar71badf92023-04-22 22:40:14 +01004257 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004258 " IF the buffer already has the desired name
4259 " AND it is empty
4260 let curbuf = bufname("%")
4261 if curbuf == '.'
4262 let curbuf = getcwd()
4263 endif
4264" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004265" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004266" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4267" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4268" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4269" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4270 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004271" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4272 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004273 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004274" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004275 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004276 " 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 +00004277
4278 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004279 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004280" 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 +00004281 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004282" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004283 " name the buffer
4284 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4285 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004287 let w:netrw_treebufnr = bufnr("%")
4288 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004289 if g:netrw_use_noswf
4290 setl nobl bt=nofile noswf
4291 else
4292 setl nobl bt=nofile
4293 endif
4294 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4295 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4296 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4297 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004298" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004299 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004300 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004301 " enter the new buffer into the s:netrwbuf dictionary
4302 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4303" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4304" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004306" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307
4308 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004310 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004312 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004313
4314 if &ft == "netrw"
4315" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4316 exe "sil! NetrwKeepj noswapfile b ".bufnum
4317" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004319" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4320 call s:NetrwEditBuf(bufnum)
4321" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004323" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004325 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004327
4328 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004330
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331 if line("$") <= 1 && getline(1) == ""
4332 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004333 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004334" 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>"))
4335" 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 +01004336" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4337 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004338
Bram Moolenaar97d62492012-11-15 21:28:22 +01004339 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004341 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004342 sil NetrwKeepj %d _
4343" 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>"))
4344" 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 +01004345" 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 +00004346 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004347
Bram Moolenaar446cb832008-06-24 21:56:24 +00004348 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4350" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004351 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004353 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354" 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>"))
4355" 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 +01004356" 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 +00004357 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004358
Bram Moolenaar446cb832008-06-24 21:56:24 +00004359 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4361" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4362" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 return 1
4364 endif
4365 endif
4366
4367 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4368 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4369 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4370 " med 1 D H
4371 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004372" 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 +00004373 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004374 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004375 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376
4377 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004378" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4379" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4380 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" 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>"))
4383" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4384" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385 return 0
4386endfun
4387
4388" ---------------------------------------------------------------------
4389" s:NetrwGetcwd: get the current directory. {{{2
4390" Change backslashes to forward slashes, if any.
4391" If doesc is true, escape certain troublesome characters
4392fun! s:NetrwGetcwd(doesc)
4393" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4394 let curdir= substitute(getcwd(),'\\','/','ge')
4395 if curdir !~ '[\/]$'
4396 let curdir= curdir.'/'
4397 endif
4398 if a:doesc
4399 let curdir= fnameescape(curdir)
4400 endif
4401" call Dret("NetrwGetcwd <".curdir.">")
4402 return curdir
4403endfun
4404
4405" ---------------------------------------------------------------------
4406" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4407fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004408" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4409" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4410 let keepsol= &l:sol
4411 setl nosol
4412
Bram Moolenaar446cb832008-06-24 21:56:24 +00004413 call s:UseBufWinVars()
4414
4415 " insure that w:netrw_liststyle is set up
4416 if !exists("w:netrw_liststyle")
4417 if exists("g:netrw_liststyle")
4418 let w:netrw_liststyle= g:netrw_liststyle
4419 else
4420 let w:netrw_liststyle= s:THINLIST
4421 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004422" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423 endif
4424
4425 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4426 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004427" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004428 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429 let dirname= "./"
4430 let curline= getline('.')
4431
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004432 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004433 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434 let s:netrw_skipbrowse= 1
4435 echo 'Pressing "s" also works'
4436
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004437 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 let s:netrw_skipbrowse= 1
4439 echo 'Press "S" to edit sorting sequence'
4440
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004441 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004442 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004446 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let s:netrw_skipbrowse= 1
4448 echo 'Pressing "a" also works'
4449
4450 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004451 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452 endif
4453
4454 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004455" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004456 NetrwKeepj norm! 0
4457 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458
4459 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004460" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004461 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4463
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004464 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004466 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004467 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468
4469 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471 let dirname= getline('.')
4472
4473 if !exists("b:netrw_cpf")
4474 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004475 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 +01004476 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 endif
4479
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004480" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004482" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4483" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004485 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 else
4487 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 endif
Enno3146d632024-07-04 19:44:42 +02004490
4491 let dict={}
4492 " save the unnamed register and register 0-9 and a
4493 let dict.a=[getreg('a'), getregtype('a')]
4494 for i in range(0, 9)
4495 let dict[i] = [getreg(i), getregtype(i)]
4496 endfor
4497 let dict.unnamed = [getreg(''), getregtype('')]
4498
Bram Moolenaarc236c162008-07-13 17:41:49 +00004499 let eofname= filestart + b:netrw_cpf + 1
4500 if eofname <= col("$")
4501 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004502 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004503 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 endif
Enno3146d632024-07-04 19:44:42 +02004506
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004508 call s:RestoreRegister(dict)
4509
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 endif
4514
4515 " symlinks are indicated by a trailing "@". Remove it before further processing.
4516 let dirname= substitute(dirname,"@$","","")
4517
4518 " executables are indicated by a trailing "*". Remove it before further processing.
4519 let dirname= substitute(dirname,"\*$","","")
4520
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004521 let &l:sol= keepsol
4522
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523" call Dret("s:NetrwGetWord <".dirname.">")
4524 return dirname
4525endfun
4526
4527" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004528" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4529" g:netrw_bufsettings will be used after the listing is produced.
4530" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531fun! s:NetrwListSettings(islocal)
4532" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004533" 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 +00004534 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004535" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4536 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4537 setl bt=nofile nobl ma nonu nowrap noro nornu
4538 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004539 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004540 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004542" call Dredir("ls!","s:NetrwListSettings")
4543" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004544 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004545 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004547 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004549 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004551" 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 +00004552" call Dret("s:NetrwListSettings")
4553endfun
4554
4555" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004556" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004557" islocal=0: remote browsing
4558" =1: local browsing
4559fun! s:NetrwListStyle(islocal)
4560" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004561
Bram Moolenaar97d62492012-11-15 21:28:22 +01004562 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563 let fname = s:NetrwGetWord()
4564 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004565 let svpos = winsaveview()
4566" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004568" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4569" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4570" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004571
Bram Moolenaar85850f32019-07-19 22:05:51 +02004572 " repoint t:netrw_lexbufnr if appropriate
4573 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4574" call Decho("set repointlexbufnr to true!")
4575 let repointlexbufnr= 1
4576 endif
4577
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 if w:netrw_liststyle == s:THINLIST
4579 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004580" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4582
4583 elseif w:netrw_liststyle == s:LONGLIST
4584 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004585" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004586 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4587
4588 elseif w:netrw_liststyle == s:WIDELIST
4589 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004590" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004591 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4592
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004593 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004594" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004595 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4596
4597 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004598 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 let g:netrw_liststyle = s:THINLIST
4600 let w:netrw_liststyle = g:netrw_liststyle
4601 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4602 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004603 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004605
4606 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4608 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004609 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004611 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" 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 +00004613
4614 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004616 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004617 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004618
Bram Moolenaar85850f32019-07-19 22:05:51 +02004619 " repoint t:netrw_lexbufnr if appropriate
4620 if exists("repointlexbufnr")
4621 let t:netrw_lexbufnr= bufnr("%")
4622" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4623 endif
4624
Bram Moolenaar13600302014-05-22 18:26:40 +02004625 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004626" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4627 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004628 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004629
4630" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4631endfun
4632
4633" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004634" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4635fun! s:NetrwBannerCtrl(islocal)
4636" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4637
Bram Moolenaar97d62492012-11-15 21:28:22 +01004638 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004639 " toggle the banner (enable/suppress)
4640 let g:netrw_banner= !g:netrw_banner
4641
4642 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004643 let svpos= winsaveview()
4644" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004645 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4646
4647 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004648 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4649 let fname= s:NetrwGetWord()
4650 sil NetrwKeepj $
4651 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4652" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4653 if result <= 0 && exists("w:netrw_bannercnt")
4654 exe "NetrwKeepj ".w:netrw_bannercnt
4655 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004656 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004657 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004658" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4659endfun
4660
4661" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004662" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4663"
4664" No bang: enters files/directories into Netrw's bookmark system
4665" No argument and in netrw buffer:
4666" if there are marked files: bookmark marked files
4667" otherwise : bookmark file/directory under cursor
4668" No argument and not in netrw buffer: bookmarks current open file
4669" Has arguments: globs them individually and bookmarks them
4670"
4671" With bang: deletes files/directories from Netrw's bookmark system
4672fun! s:NetrwBookmark(del,...)
4673" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4674 if a:0 == 0
4675 if &ft == "netrw"
4676 let curbufnr = bufnr("%")
4677
4678 if exists("s:netrwmarkfilelist_{curbufnr}")
4679 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004681 let svpos = winsaveview()
4682" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004683 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004684 for fname in s:netrwmarkfilelist_{curbufnr}
4685 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4686 endfor
4687 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4688 call s:NetrwUnmarkList(curbufnr,curdir)
4689 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004690" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4691 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004692 else
4693 let fname= s:NetrwGetWord()
4694 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4695 endif
4696
4697 else
4698 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004699" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004700 let fname= expand("%")
4701 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4702 endif
4703
4704 else
4705 " bookmark specified files
4706 " attempts to infer if working remote or local
4707 " by deciding if the current file begins with an url
4708 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004709 let islocal= expand("%") !~ '^\a\{3,}://'
4710" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004711 let i = 1
4712 while i <= a:0
4713 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004714 if v:version > 704 || (v:version == 704 && has("patch656"))
4715 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004717 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004719 else
4720 let mbfiles= [a:{i}]
4721 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4726 endfor
4727 let i= i + 1
4728 endwhile
4729 endif
4730
4731 " update the menu
4732 call s:NetrwBookmarkMenu()
4733
4734" call Dret("s:NetrwBookmark")
4735endfun
4736
4737" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004738" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4739" .2.[cnt] for bookmarks, and
4740" .3.[cnt] for history
4741" (see s:NetrwMenu())
4742fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004743 if !exists("s:netrw_menucnt")
4744 return
4745 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004746" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004747
4748 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004749 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004750 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004751" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004752 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4753 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004754 endif
4755 if !exists("s:netrw_initbookhist")
4756 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004757 endif
4758
4759 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004760 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004761 let cnt= 1
4762 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765
4766 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004768
4769 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004770 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 +01004771 let cnt= cnt + 1
4772 endfor
4773
4774 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775
4776 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004777 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 let first = 1
4780 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 if exists("g:netrw_dirhist_{cnt}")
4785 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004786" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4788 endif
4789 let first = 0
4790 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4791 if cnt < 0
4792 let cnt= cnt + g:netrw_dirhistmax
4793 endif
4794 endwhile
4795 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004796
Bram Moolenaar9964e462007-05-05 17:54:07 +00004797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004798" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004799endfun
4800
4801" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004802" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4803" directory and a new directory name. Also, if the
4804" "new directory name" is actually a file,
4805" NetrwBrowseChgDir() edits the file.
4806fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004807" 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 +01004808" 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 +00004809
Bram Moolenaar97d62492012-11-15 21:28:22 +01004810 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004811 if !exists("b:netrw_curdir")
4812 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4813 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004814 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004815" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4816" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004817" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004818" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004820 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004821" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004823 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004824" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004825 call s:SavePosn(s:netrw_posn)
4826 NetrwKeepj call s:NetrwOptionsSave("s:")
4827 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004828 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004829 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004830 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004831 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004832 endif
4833 let newdir = a:newdir
4834 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004835 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004836" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004837" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004839
4840 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004841" 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 +01004842 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004843" 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 +01004844 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004845 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004846" 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 +01004847 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" 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 +02004849 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004850 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004851 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004852 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004853" 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 +01004854 endif
4855 endif
4856" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004857" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004858 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004859
Bram Moolenaar446cb832008-06-24 21:56:24 +00004860 " set up o/s-dependent directory recognition pattern
4861 if has("amiga")
4862 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004863 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 let dirpat= '[\/]$'
4865 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867
4868 if dirname !~ dirpat
4869 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004870 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004872" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 endif
4874
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004875" 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 +01004876 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004877 " ------------------------------
4878 " NetrwBrowseChgDir: edit a file {{{3
4879 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004880" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004881
Bram Moolenaar97d62492012-11-15 21:28:22 +01004882 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004883 let s:rexposn_{bufnr("%")}= winsaveview()
4884" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4886" 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 +01004887
Bram Moolenaar446cb832008-06-24 21:56:24 +00004888 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004889" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4890" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004891" let newdir = s:NetrwTreePath(s:netrw_treetop)
4892" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004893 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004894 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4895" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4896 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004897 if dirname =~ '/$'
4898 let dirname= dirname.newdir
4899 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004900 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004902" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4903" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004905" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004907 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004910" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004911 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004913" 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 +02004914 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004915 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004917" " 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 +01004918 if type(g:netrw_browse_split) == 3
4919 " open file in server
4920 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004921" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004922 call s:NetrwServerEdit(a:islocal,dirname)
4923" call Dret("s:NetrwBrowseChgDir")
4924 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004925
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004926 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004927 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004928" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004929 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4930 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004931 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004932 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004933 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004934 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004935
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004937 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004938" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004939 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4940 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004941 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004942 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004943 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004944 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004945
Bram Moolenaar446cb832008-06-24 21:56:24 +00004946 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004947 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004948" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004949 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004950 if !exists("b:netrw_curdir")
4951 let b:netrw_curdir= getcwd()
4952 endif
4953 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004954
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004956 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004957" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004959 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004961 return
4962 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004963 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004964
Bram Moolenaar9964e462007-05-05 17:54:07 +00004965 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004967" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 call s:NetrwMenu(0)
4969 " optional change to window
4970 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004971" 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 +02004972 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004973 " if g:netrw_chgwin is set to one more than the last window, then
4974 " vertically split the last window to make that window available.
4975 let curwin= winnr()
4976 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4977 vs
4978 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004979 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004980 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004981 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004982 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004983 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004984
Bram Moolenaar9964e462007-05-05 17:54:07 +00004985 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004986
Bram Moolenaar446cb832008-06-24 21:56:24 +00004987 " the point where netrw actually edits the (local) file
4988 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004989 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004990 if !&mod
4991 " if e the new file would fail due to &mod, then don't change any of the flags
4992 let dolockout= 1
4993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004994 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004995" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004996 " some like c-^ to return to the last edited file
4997 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004998 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4999 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005000 call s:NetrwEditFile("e","",dirname)
5001" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005002 " COMBAK -- cuc cul related
5003 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005004 if &hidden || &bufhidden == "hide"
5005 " file came from vim's hidden storage. Don't "restore" options with it.
5006 let dorestore= 0
5007 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005008 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005009" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005010 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005011
5012 " handle g:Netrw_funcref -- call external-to-netrw functions
5013 " This code will handle g:Netrw_funcref as an individual function reference
5014 " or as a list of function references. It will ignore anything that's not
5015 " a function reference. See :help Funcref for information about function references.
5016 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005018 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005020 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005024 if type(Fncref) == 2
5025 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005026 endif
5027 endfor
5028 endif
5029 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005030 endif
5031
5032 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005033 " ----------------------------------------------------
5034 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5035 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005036" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005037 let dirname = newdir
5038 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005039 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005040 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005041
5042 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005043 " ---------------------------------------------
5044 " NetrwBrowseChgDir: refresh the directory list {{{3
5045 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005046" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005047 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005048 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005049
5050 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005051 " --------------------------------------
5052 " NetrwBrowseChgDir: go up one directory {{{3
5053 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005054" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055
5056 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5057 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005058" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5059" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005060 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005062 endif
5063
5064 if has("amiga")
5065 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005067 if a:islocal
5068 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5069 let dirname= substitute(dirname,'/$','','')
5070 else
5071 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5072 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005073" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005074
Nir Lichtman1e34b952024-05-08 19:19:34 +02005075 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005076 " windows
5077 if a:islocal
5078 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5079 if dirname == ""
5080 let dirname= '/'
5081 endif
5082 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005083 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005084 endif
5085 if dirname =~ '^\a:$'
5086 let dirname= dirname.'/'
5087 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005088" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005089
Bram Moolenaar446cb832008-06-24 21:56:24 +00005090 else
5091 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005092" 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 +00005093 if a:islocal
5094 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5095 if dirname == ""
5096 let dirname= '/'
5097 endif
5098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005101" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005103 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005104 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105
5106 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005107 " --------------------------------------
5108 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5109 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005110" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005111 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5112" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005113 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005114 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005115" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5116 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005118 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005119" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005120 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005121 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123
5124 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005125" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 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
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005133 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005134" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 if has_key(w:netrw_treedict,treedir."/")
5137 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005138" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 let haskey = 1
5140 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005141" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 endif
5143 endif
5144
5145 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005146" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 if !haskey && treedir =~ '/$'
5148 let treedir= substitute(treedir,'/$','','')
5149 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005150" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005151 let haskey = 1
5152 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005153" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005154 endif
5155 endif
5156
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 if haskey
5159 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5163" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005164 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 else
5166 " go down one directory
5167 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5169" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005170 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005171 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005172" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005173 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174
5175 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005176 " ----------------------------------------
5177 " NetrwBrowseChgDir: Go down one directory {{{3
5178 " ----------------------------------------
5179 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005180" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005181 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005182 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005183 endif
5184
Bram Moolenaar97d62492012-11-15 21:28:22 +01005185 " --------------------------------------
5186 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5187 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005188 if dorestore
5189 " dorestore is zero'd when a local file was hidden or bufhidden;
5190 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005191" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005192 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005193" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005195 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005196 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005198 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5200" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" 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 +02005203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5205" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005206 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005208 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005209 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005210 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005211 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005212
Bram Moolenaar446cb832008-06-24 21:56:24 +00005213" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5214 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215endfun
5216
5217" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005218" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5219" for thin, long, and wide: cursor placed just after banner
5220" for tree, keeps cursor on current filename
5221fun! s:NetrwBrowseUpDir(islocal)
5222" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005223 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5224 " this test needed because occasionally this function seems to be incorrectly called
5225 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005226 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005227 " directories.
5228" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5229 return
5230 endif
5231
Bram Moolenaara6878372014-03-22 21:02:50 +01005232 norm! 0
5233 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005234" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005235 let curline= getline(".")
5236 let swwline= winline() - 1
5237 if exists("w:netrw_treetop")
5238 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005239 elseif exists("b:netrw_curdir")
5240 let w:netrw_treetop= b:netrw_curdir
5241 else
5242 let w:netrw_treetop= getcwd()
5243 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005245 let curfile = getline(".")
5246 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005247 if a:islocal
5248 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5249 else
5250 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5251 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005252" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5253" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5254 if w:netrw_treetop == '/'
5255 keepj call search('^\M'.curfile,"w")
5256 elseif curfile == '../'
5257 keepj call search('^\M'.curfile,"wb")
5258 else
5259" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5260 while 1
5261 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5262 let treepath= s:NetrwTreePath(w:netrw_treetop)
5263" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5264 if treepath == curpath
5265 break
5266 endif
5267 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005268 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005269
Bram Moolenaara6878372014-03-22 21:02:50 +01005270 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005271" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005273 if exists("b:netrw_curdir")
5274 let curdir= b:netrw_curdir
5275 else
5276 let curdir= expand(getcwd())
5277 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005278 if a:islocal
5279 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5280 else
5281 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5282 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005283 call s:RestorePosn(s:netrw_posn)
5284 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005285 let curdir= '\<'. escape(curdir, '~'). '/'
5286 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005287 endif
5288" call Dret("s:NetrwBrowseUpDir")
5289endfun
5290
5291" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005292" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005293" given filename; typically this means given their extension.
5294" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005295fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005296 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005297" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005298
Bram Moolenaar91359012019-11-30 17:57:03 +01005299 if a:remote == 0 && isdirectory(a:fname)
5300 " if its really just a local directory, then do a "gf" instead
5301" 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 +01005302" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5303 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005304" call Dret("netrw#BrowseX")
5305 return
5306 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5307 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5308" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5309" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5310" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5311" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5312 norm! gf
5313" call Dret("netrw#BrowseX")
5314 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005315 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005316" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005317
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005318 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5319 let remote = a:remote
5320 else
5321 let remote = 0
5322 endif
5323
Bram Moolenaar97d62492012-11-15 21:28:22 +01005324 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005325 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005326" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005327
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5329 let awkeep = &aw
5330 set noaw
5331
Bram Moolenaar5c736222010-01-06 20:54:52 +01005332 " special core dump handler
5333 if a:fname =~ '/core\(\.\d\+\)\=$'
5334 if exists("g:Netrw_corehandler")
5335 if type(g:Netrw_corehandler) == 2
5336 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005337" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005338 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005339 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005341" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005343 if type(Fncref) == 2
5344 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 endif
5346 endfor
5347 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005348" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005349 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005350 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005351 let &aw= awkeep
5352" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 return
5354 endif
5355 endif
5356
Bram Moolenaar446cb832008-06-24 21:56:24 +00005357 " set up the filename
5358 " (lower case the extension, make a local copy of a remote file)
5359 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005360 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005361 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005362 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005363 if exten =~ "[\\/]"
5364 let exten= ""
5365 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005366" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005368 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005369 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005370" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005371 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005372 call netrw#NetRead(3,a:fname)
5373 " attempt to rename tempfile
5374 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005375 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005376" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5377" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005378 if s:netrw_tmpfile != newname && newname != ""
5379 if rename(s:netrw_tmpfile,newname) == 0
5380 " renaming succeeded
5381" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5382 let fname= newname
5383 else
5384 " renaming failed
5385" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5386 let fname= s:netrw_tmpfile
5387 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005388 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 let fname= s:netrw_tmpfile
5390 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005391 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005392" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005393 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005394 " special ~ handler for local
5395 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005396" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5397 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005398 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005400" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5401" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005403 " set up redirection (avoids browser messages)
5404 " by default, g:netrw_suppress_gx_mesg is true
5405 if g:netrw_suppress_gx_mesg
5406 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005407 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005408 let redir= substitute(&srr,"%s","nul","")
5409 else
5410 let redir= substitute(&srr,"%s","/dev/null","")
5411 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005412 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005413 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005414 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005415 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005417 else
5418 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005420" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005422 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005424" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425 if g:netrw_browsex_viewer =~ '\s'
5426 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5427 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5428 let oviewer = ''
5429 let cnt = 1
5430 while !executable(viewer) && viewer != oviewer
5431 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5432 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5433 let cnt = cnt + 1
5434 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005435" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 endwhile
5437 else
5438 let viewer = g:netrw_browsex_viewer
5439 let viewopt = ""
5440 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005441" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 endif
5443
5444 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005445" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005447" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448 let ret= netrwFileHandlers#Invoke(exten,fname)
5449
5450 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005451" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005452 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453 let ret= v:shell_error
5454
Nir Lichtman1e34b952024-05-08 19:19:34 +02005455 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005456" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005457 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005458 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005459 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005460 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005461 else
5462 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5463 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005464 let ret= v:shell_error
5465
Bram Moolenaar97d62492012-11-15 21:28:22 +01005466 elseif has("win32unix")
5467 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005468" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005472 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005475 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005477 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005478 else
5479 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5480 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005481 let ret= v:shell_error
5482
Bram Moolenaar85850f32019-07-19 22:05:51 +02005483 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005484" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5485 if a:fname =~ '^https\=://'
5486 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5487 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005488" call Decho("fname<".fname.">")
5489" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005490 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5491
5492 else
5493 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5494 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005495 let ret= v:shell_error
5496
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005497 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5498" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5499 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5500 let ret= v:shell_error
5501
5502 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5503" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5504 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5505 let ret= v:shell_error
5506
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005507 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005508" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005509 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005510 let ret= v:shell_error
5511
5512 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005513" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005514 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005515 let ret= v:shell_error
5516
5517 else
5518 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005519" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005520 let ret= netrwFileHandlers#Invoke(exten,fname)
5521 endif
5522
5523 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5524 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005525" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005526 let ret= netrwFileHandlers#Invoke(exten,fname)
5527 endif
5528
Bram Moolenaarc236c162008-07-13 17:41:49 +00005529 " restoring redraw! after external file handlers
5530 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531
5532 " cleanup: remove temporary file,
5533 " delete current buffer if success with handler,
5534 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005535 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005536 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005537" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005538"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005539" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005540" endif
5541
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005542 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005543 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005545 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005547 if use_ctrlo
5548 exe "sil! NetrwKeepj norm! \<c-o>"
5549 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005551" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005552 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005553 let @@ = ykeep
5554 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556" call Dret("netrw#BrowseX")
5557endfun
5558
5559" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005560" netrw#GX: gets word under cursor for gx support {{{2
5561" See also: netrw#BrowseXVis
5562" netrw#BrowseX
5563fun! netrw#GX()
5564" call Dfunc("netrw#GX()")
5565 if &ft == "netrw"
5566 let fname= s:NetrwGetWord()
5567 else
5568 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5569 endif
5570" call Dret("netrw#GX <".fname.">")
5571 return fname
5572endfun
5573
5574" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005575" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5576fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005577 let dict={}
5578 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005579 norm! gv"ay
5580 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005581 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005582 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005583endfun
5584
5585" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005586" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5587" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5588" to become an unlisted buffer, so in that case don't bwipe it.
5589fun! s:NetrwBufRename(newname)
5590" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5591" call Dredir("ls!","s:NetrwBufRename (before rename)")
5592 let oldbufname= bufname(bufnr("%"))
5593" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5594
5595 if oldbufname != a:newname
5596" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5597 let b:junk= 1
5598" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5599 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005600" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005601 let oldbufnr= bufnr(oldbufname)
5602" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5603" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5604 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5605" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5606 exe "bwipe! ".oldbufnr
5607" else " Decho
5608" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005609" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5610" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5611" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005612 endif
5613" call Dredir("ls!","s:NetrwBufRename (after rename)")
5614" else " Decho
5615" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5616 endif
5617
5618" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5619endfun
5620
5621" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005622" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005623fun! netrw#CheckIfRemote(...)
5624" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5625 if a:0 > 0
5626 let curfile= a:1
5627 else
5628 let curfile= expand("%")
5629 endif
5630" call Decho("curfile<".curfile.">")
5631 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005632" call Dret("netrw#CheckIfRemote 1")
5633 return 1
5634 else
5635" call Dret("netrw#CheckIfRemote 0")
5636 return 0
5637 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005638endfun
5639
5640" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5642fun! s:NetrwChgPerm(islocal,curdir)
5643" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005644 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645 call inputsave()
5646 let newperm= input("Enter new permission: ")
5647 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005648 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5649 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5650" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005651 call system(chgperm)
5652 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005653 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 endif
5655 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005658 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005659" call Dret("s:NetrwChgPerm")
5660endfun
5661
5662" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005663" s:CheckIfKde: checks if kdeinit is running {{{2
5664" Returns 0: kdeinit not running
5665" 1: kdeinit is running
5666fun! s:CheckIfKde()
5667" call Dfunc("s:CheckIfKde()")
5668 " seems kde systems often have gnome-open due to dependencies, even though
5669 " gnome-open's subsidiary display tools are largely absent. Kde systems
5670 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5671 if !exists("s:haskdeinit")
5672 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005673 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 if v:shell_error
5675 let s:haskdeinit = 0
5676 endif
5677 else
5678 let s:haskdeinit= 0
5679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005680" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005681 endif
5682
5683" call Dret("s:CheckIfKde ".s:haskdeinit)
5684 return s:haskdeinit
5685endfun
5686
5687" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005688" s:NetrwClearExplore: clear explore variables (if any) {{{2
5689fun! s:NetrwClearExplore()
5690" call Dfunc("s:NetrwClearExplore()")
5691 2match none
5692 if exists("s:explore_match") |unlet s:explore_match |endif
5693 if exists("s:explore_indx") |unlet s:explore_indx |endif
5694 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5695 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5696 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5697 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5698 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5699 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5700 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5701" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005702" call Dret("s:NetrwClearExplore")
5703endfun
5704
5705" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005706" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5707fun! s:NetrwEditBuf(bufnum)
5708" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5709 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5710" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5711 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5712 else
5713" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005714 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005715 endif
5716" call Dret("s:NetrwEditBuf")
5717endfun
5718
5719" ---------------------------------------------------------------------
5720" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5721" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5722fun! s:NetrwEditFile(cmd,opt,fname)
5723" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5724 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5725" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5726 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5727 else
5728" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005729 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5730 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5731 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005732 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5733 endif
5734" call Dret("s:NetrwEditFile")
5735endfun
5736
5737" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005738" s:NetrwExploreListUniq: {{{2
5739fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005740" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005741
5742 " this assumes that the list is already sorted
5743 let newexplist= []
5744 for member in a:explist
5745 if !exists("uniqmember") || member != uniqmember
5746 let uniqmember = member
5747 let newexplist = newexplist + [ member ]
5748 endif
5749 endfor
5750
Bram Moolenaar15146672011-10-20 22:22:38 +02005751" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005752 return newexplist
5753endfun
5754
5755" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005756" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5757fun! s:NetrwForceChgDir(islocal,newdir)
5758" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005759 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005760 if a:newdir !~ '/$'
5761 " ok, looks like force is needed to get directory-style treatment
5762 if a:newdir =~ '@$'
5763 let newdir= substitute(a:newdir,'@$','/','')
5764 elseif a:newdir =~ '[*=|\\]$'
5765 let newdir= substitute(a:newdir,'.$','/','')
5766 else
5767 let newdir= a:newdir.'/'
5768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005769" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005770 else
5771 " should already be getting treatment as a directory
5772 let newdir= a:newdir
5773 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005774 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005775 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005776 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005777" call Dret("s:NetrwForceChgDir")
5778endfun
5779
5780" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005782" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5783" expr : this is the expression to follow the directory. Will use s:ComposePath()
5784" pare =1: remove the current directory from the resulting glob() filelist
5785" =0: leave the current directory in the resulting glob() filelist
5786fun! s:NetrwGlob(direntry,expr,pare)
5787" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005788 if netrw#CheckIfRemote()
5789 keepalt 1sp
5790 keepalt enew
5791 let keep_liststyle = w:netrw_liststyle
5792 let w:netrw_liststyle = s:THINLIST
5793 if s:NetrwRemoteListing() == 0
5794 keepj keepalt %s@/@@
5795 let filelist= getline(1,$)
5796 q!
5797 else
5798 " remote listing error -- leave treedict unchanged
5799 let filelist= w:netrw_treedict[a:direntry]
5800 endif
5801 let w:netrw_liststyle= keep_liststyle
5802 else
Christian Brabandt14879472024-06-13 21:25:35 +02005803 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005804 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005805 " escape [ so it is not detected as wildcard character, see :h wildcard
5806 let path= substitute(path, '[', '[[]', 'g')
5807 endif
5808 if v:version > 704 || (v:version == 704 && has("patch656"))
5809 let filelist= glob(path,0,1,1)
5810 else
5811 let filelist= glob(path,0,1)
5812 endif
5813 if a:pare
5814 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5815 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005816 endif
5817" call Dret("s:NetrwGlob ".string(filelist))
5818 return filelist
5819endfun
5820
5821" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005822" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5823fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005824" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005825 if a:newfile =~ '[/@*=|\\]$'
5826 let newfile= substitute(a:newfile,'.$','','')
5827 else
5828 let newfile= a:newfile
5829 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005830 if a:islocal
5831 call s:NetrwBrowseChgDir(a:islocal,newfile)
5832 else
5833 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5834 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005835" call Dret("s:NetrwForceFile")
5836endfun
5837
5838" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005839" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5840" and switches the hiding mode. The actual hiding is done by
5841" s:NetrwListHide().
5842" g:netrw_hide= 0: show all
5843" 1: show not-hidden files
5844" 2: show hidden files only
5845fun! s:NetrwHide(islocal)
5846" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005847 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005848 let svpos= winsaveview()
5849" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005850
5851 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5853" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005854
5855 " hide the files in the markfile list
5856 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005857" 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 +00005858 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5859 " remove fname from hiding list
5860 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5861 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5862 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005863" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864 else
5865 " append fname to hiding list
5866 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5867 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5868 else
5869 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5870 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005871" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 endif
5873 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005874 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 let g:netrw_hide= 1
5876
5877 else
5878
5879 " switch between show-all/show-not-hidden/show-hidden
5880 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005884 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885" call Dret("NetrwHide")
5886 return
5887 endif
5888 endif
5889
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005890 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005891" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5892 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005893 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005895endfun
5896
5897" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005898" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5899fun! s:NetrwHideEdit(islocal)
5900" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5901
5902 let ykeep= @@
5903 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005904 let svpos= winsaveview()
5905" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005906
5907 " get new hiding list from user
5908 call inputsave()
5909 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5910 call inputrestore()
5911 let g:netrw_list_hide= newhide
5912" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5913
5914 " refresh the listing
5915 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5916
5917 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005918" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5919 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005920 let @@= ykeep
5921
5922" call Dret("NetrwHideEdit")
5923endfun
5924
5925" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005926" s:NetrwHidden: invoked by "gh" {{{2
5927fun! s:NetrwHidden(islocal)
5928" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005929 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005931 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005932" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005933
5934 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005935 " remove .file pattern from hiding list
5936" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005938 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5941 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5944 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005945 if g:netrw_list_hide =~ '^,'
5946 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948
5949 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005950 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005951" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5952 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005953 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954" call Dret("s:NetrwHidden")
5955endfun
5956
5957" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005958" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5959fun! s:NetrwHome()
5960 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005961 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005962 else
5963 " go to vim plugin home
5964 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005965 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005966 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005967 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968 let home= basehome."/.vim"
5969 break
5970 endif
5971 endfor
5972 if home == ""
5973 " just pick the first directory
5974 let home= substitute(&rtp,',.*$','','')
5975 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005976 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005977 let home= substitute(home,'/','\\','g')
5978 endif
5979 endif
5980 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005986 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005987" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988 call mkdir(home)
5989 endif
5990 endif
5991 let g:netrw_home= home
5992 return home
5993endfun
5994
5995" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5997fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005998 if exists("s:netrwdrag")
5999 return
6000 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006001 if &ft != "netrw"
6002 return
6003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006004" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006005
Bram Moolenaar97d62492012-11-15 21:28:22 +01006006 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006007 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006008 while getchar(0) != 0
6009 "clear the input stream
6010 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006011 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006012 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006013 let mouse_lnum = v:mouse_lnum
6014 let wlastline = line('w$')
6015 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006016" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6017" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6019 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006020 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006021" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6022 return
6023 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006024 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006025 " 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 +01006026 " without this test when its disabled.
6027 " 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 +01006028" 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 +01006029 if v:mouse_col > virtcol('.')
6030 let @@= ykeep
6031" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6032 return
6033 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 if a:islocal
6036 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006037 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006038 endif
6039 else
6040 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006041 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006042 endif
6043 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006044 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006045" call Dret("s:NetrwLeftmouse")
6046endfun
6047
6048" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006049" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6050fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006051 if &ft != "netrw"
6052 return
6053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006054" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6055 call s:NetrwMarkFileTgt(a:islocal)
6056" call Dret("s:NetrwCLeftmouse")
6057endfun
6058
6059" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6061" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006062" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063" a:islocal=2 : <c-r> used, remote
6064" a:islocal=3 : <c-r> used, local
6065fun! s:NetrwServerEdit(islocal,fname)
6066" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6067 let islocal = a:islocal%2 " =0: remote =1: local
6068 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006069" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006073 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006076 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6078 unlet s:netrw_browse_split_{winnr()}
6079 endif
6080 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6081" call Dret("s:NetrwServerEdit")
6082 return
6083 endif
6084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088
6089 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 let srvrname = g:netrw_browse_split[0]
6092 let tabnum = g:netrw_browse_split[1]
6093 let winnum = g:netrw_browse_split[2]
6094
6095 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097
6098 if !ctrlr
6099 " user must have closed the server window and the user did not use <c-r>, but
6100 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006103 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 endif
6105 let g:netrw_browse_split= 0
6106 if exists("s:netrw_browse_split_".winnr())
6107 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6108 endif
6109 call s:NetrwBrowseChgDir(islocal,a:fname)
6110" call Dret("s:NetrwServerEdit")
6111 return
6112
6113 elseif has("win32") && executable("start")
6114 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 call system("start gvim --servername ".srvrname)
6117
6118 else
6119 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121 call system("gvim --servername ".srvrname)
6122 endif
6123 endif
6124
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6127 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129
6130 else
6131
6132 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6133
6134 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006135" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006137 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006138 endif
6139 let g:netrw_browse_split= 0
6140 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6141" call Dret("s:NetrwServerEdit")
6142 return
6143
6144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 if has("win32") && executable("start")
6147 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 call system("start gvim --servername ".g:netrw_servername)
6150 else
6151 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006153 call system("gvim --servername ".g:netrw_servername)
6154 endif
6155 endif
6156 endif
6157
6158 while 1
6159 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006160" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6161 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006162 break
6163 catch /^Vim\%((\a\+)\)\=:E241/
6164 sleep 200m
6165 endtry
6166 endwhile
6167
6168 if exists("g:netrw_browse_split")
6169 if type(g:netrw_browse_split) != 3
6170 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6171 endif
6172 unlet g:netrw_browse_split
6173 endif
6174 let g:netrw_browse_split= [g:netrw_servername,1,1]
6175 endif
6176
6177 else
6178 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6179 endif
6180
6181" call Dret("s:NetrwServerEdit")
6182endfun
6183
6184" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006185" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6186fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006187 if &ft != "netrw"
6188 return
6189 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006190" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006191
Bram Moolenaar8d043172014-01-23 14:24:41 +01006192 let s:ngw= s:NetrwGetWord()
6193 call s:NetrwMarkFile(a:islocal,s:ngw)
6194
6195" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006196endfun
6197
6198" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006199" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6200" Used to mark multiple files.
6201fun! s:NetrwSLeftdrag(islocal)
6202" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6203 if !exists("s:netrwdrag")
6204 let s:netrwdrag = winnr()
6205 if a:islocal
6206 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006207 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006208 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006209 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006210 endif
6211 let ngw = s:NetrwGetWord()
6212 if !exists("s:ngw") || s:ngw != ngw
6213 call s:NetrwMarkFile(a:islocal,ngw)
6214 endif
6215 let s:ngw= ngw
6216" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6217endfun
6218
6219" ---------------------------------------------------------------------
6220" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6221fun! s:NetrwSLeftrelease(islocal)
6222" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6223 if exists("s:netrwdrag")
6224 nunmap <s-leftrelease>
6225 let ngw = s:NetrwGetWord()
6226 if !exists("s:ngw") || s:ngw != ngw
6227 call s:NetrwMarkFile(a:islocal,ngw)
6228 endif
6229 if exists("s:ngw")
6230 unlet s:ngw
6231 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006232 unlet s:netrwdrag
6233 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006234" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006235endfun
6236
6237" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006238" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6239" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006241" 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 +02006242" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006243 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006244
6245 " 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 +02006246 " How-it-works: take the hiding command, convert it into a range.
6247 " Duplicate characters don't matter.
6248 " Remove all such characters from the '/~@#...890' string.
6249 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006250" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006252 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006253" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006254
6255 while listhide != ""
6256 if listhide =~ ','
6257 let hide = substitute(listhide,',.*$','','e')
6258 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6259 else
6260 let hide = listhide
6261 let listhide = ""
6262 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006263" 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 +01006264 if g:netrw_sort_by =~ '^[ts]'
6265 if hide =~ '^\^'
6266" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6267 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6268 elseif hide =~ '^\\(\^'
6269 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6270 endif
6271" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6272 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273
6274 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006275" 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 +00006276 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006281 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006282 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006283" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006287 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006291 endif
6292
Bram Moolenaaradc21822011-04-01 18:03:16 +02006293 " remove any blank lines that have somehow remained.
6294 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006295 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006296
Bram Moolenaar97d62492012-11-15 21:28:22 +01006297 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299endfun
6300
6301" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006305" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306
Bram Moolenaar97d62492012-11-15 21:28:22 +01006307 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 " get name of new directory from user. A bare <CR> will skip.
6309 " if its currently a directory, also request will be skipped, but with
6310 " a message.
6311 call inputsave()
6312 let newdirname= input("Please give directory name: ")
6313 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315
6316 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006317 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006318" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 return
6320 endif
6321
6322 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006323" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324
6325 " Local mkdir:
6326 " sanity checks
6327 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006328" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6329 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006330 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006333 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006334" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 return
6336 endif
6337 if s:FileReadable(fullnewdir)
6338 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006339 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006341 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006342" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 return
6344 endif
6345
6346 " requested new local directory is neither a pre-existing file or
6347 " directory, so make it!
6348 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006349 if has("unix")
6350 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6351 else
6352 call mkdir(fullnewdir,"p")
6353 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006354 else
6355 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006356 if s:NetrwLcd(b:netrw_curdir)
6357" call Dret("s:NetrwMakeDir : lcd failure")
6358 return
6359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006361 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006362 if v:shell_error != 0
6363 let @@= ykeep
6364 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 +01006365" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006366 return
6367 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006368 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006369" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006370 if s:NetrwLcd(netrw_origdir)
6371" call Dret("s:NetrwBrowse : lcd failure")
6372 return
6373 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374 endif
6375 endif
6376
6377 if v:shell_error == 0
6378 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006379" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380 let svpos= winsaveview()
6381" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006383" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6384 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006385 elseif !exists("g:netrw_quiet")
6386 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6387 endif
6388" redraw!
6389
6390 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006391 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6394 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006395 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396 if v:shell_error == 0
6397 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006398 let svpos= winsaveview()
6399" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006400 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006401" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6402 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006404 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 endif
6406" redraw!
6407
6408 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006409 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006410 let svpos= winsaveview()
6411" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006412" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006414" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006415 let remotepath= b:netrw_fname
6416 else
6417 let remotepath= ""
6418 endif
6419 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006420 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006421" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6422 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006423
Bram Moolenaar446cb832008-06-24 21:56:24 +00006424 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006425 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426 let svpos= winsaveview()
6427" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 let remotepath= b:netrw_fname
6432 else
6433 let remotepath= ""
6434 endif
6435 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006436 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6438 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006439 endif
6440
Bram Moolenaar97d62492012-11-15 21:28:22 +01006441 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006442" call Dret("s:NetrwMakeDir")
6443endfun
6444
6445" ---------------------------------------------------------------------
6446" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6447fun! s:TreeSqueezeDir(islocal)
6448" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6449 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6450 " its a tree-listing style
6451 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006453 let depth = strchars(substitute(curdepth,' ','','g'))
6454 let srch = -1
6455" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6456" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006458" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6459 if depth >= 2
6460 NetrwKeepj norm! 0
6461 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6462 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6463" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6464" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6465 elseif depth == 1
6466 NetrwKeepj norm! 0
6467 let treedepthchr= substitute(s:treedepthstring,' ','','')
6468 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6469" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6470 endif
6471 if srch > 0
6472" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6473 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6474 exe srch
6475 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006476 endif
6477" call Dret("s:TreeSqueezeDir")
6478endfun
6479
6480" ---------------------------------------------------------------------
6481" s:NetrwMaps: {{{2
6482fun! s:NetrwMaps(islocal)
6483" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6484
Bram Moolenaar85850f32019-07-19 22:05:51 +02006485 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 if !hasmapto("<Plug>NetrwReturn")
6489 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6492 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006493" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6495 endif
6496 endif
6497 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 endif
6500
Bram Moolenaar85850f32019-07-19 22:05:51 +02006501 " generate default <Plug> maps {{{3
6502 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006503 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006504 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6505 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6506 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6507 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6508 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6509 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6510 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6511 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6512 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6513 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6514" ---------------------------------------------------------------------
6515" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6516" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6517" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6518" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6519" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6520" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6521" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6522" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6523" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6524" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6525" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6526" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6527" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6528" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6529" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6530" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6531" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6532" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6533" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6534" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6535" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6536" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6537" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6538" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6539" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6540" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6541" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6542" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6543" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6544" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6545" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6546" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6547" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6548" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6549" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6550" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6551" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6552" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6553" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6554" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6555" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6556" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6557" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6558" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6559" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6560" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6561" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6562
Bram Moolenaara6878372014-03-22 21:02:50 +01006563 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006564" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006565 " local normal-mode maps {{{3
6566 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6577" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6579 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6580 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006581 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006582 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006583 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6584 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6586 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006587 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6588 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6589 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6591 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6593 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6594 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006601 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6604 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6605 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6610 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6612 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6613 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6621 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6622 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6624 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006625
6626 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 +01006627 if !hasmapto('<Plug>NetrwHideEdit')
6628 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006629 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 if !hasmapto('<Plug>NetrwRefresh')
6632 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006634 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 +01006635 if s:didstarstar || !mapcheck("<s-down>","n")
6636 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 endif
6638 if s:didstarstar || !mapcheck("<s-up>","n")
6639 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 if !hasmapto('<Plug>NetrwTreeSqueeze')
6642 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 endif
6644 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6646 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006647 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6648 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6649 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6650 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6651 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6652 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6653 imap <buffer> <leftmouse> <Plug>ILeftmouse
6654 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006655 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6656 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6657 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6658 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6659 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006660 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006661 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6662 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6665 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6667 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6668 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6669 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6670 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006671 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6672
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 " support user-specified maps
6674 call netrw#UserMaps(1)
6675
Bram Moolenaar85850f32019-07-19 22:05:51 +02006676 else
6677 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006679 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006680 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6691" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006692 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6693 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6694 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6696 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6697 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6699 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006700 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006701 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6704 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6706 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6707 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006714 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6719 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006720 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6723 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006724 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6726 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006727 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006728 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 +01006729 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6730 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6732 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6733 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6734 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6735 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6736 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6737 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006738 if !hasmapto('<Plug>NetrwHideEdit')
6739 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 endif
6741 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6742 if !hasmapto('<Plug>NetrwRefresh')
6743 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006744 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006745 if !hasmapto('<Plug>NetrwTreeSqueeze')
6746 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006747 endif
6748 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006749
6750 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006751 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006752
6753 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6754 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006756 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006758 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006760 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006762 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006764 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6766 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6767 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006770 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6771 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006772 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6775 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6777 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6778 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006780 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006781
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782 " support user-specified maps
6783 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006784 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006785
6786" call Dret("s:NetrwMaps")
6787endfun
6788
6789" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006790" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006791" If -buffer, the command is only available from within netrw buffers
6792" Otherwise, the command is available from any window, so long as netrw
6793" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006794fun! s:NetrwCommands(islocal)
6795" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6796
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006797 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6798 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006799 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 +01006800 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006801 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006802 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006803 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006804 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006805 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006806
6807" call Dret("s:NetrwCommands")
6808endfun
6809
6810" ---------------------------------------------------------------------
6811" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6812" glob()ing only works with local files
6813fun! s:NetrwMarkFiles(islocal,...)
6814" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815 let curdir = s:NetrwGetCurdir(a:islocal)
6816 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006817 while i <= a:0
6818 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006819 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006820 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006821 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006822 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006823 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 else
6825 let mffiles= [a:{i}]
6826 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006828 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006830 call s:NetrwMarkFile(a:islocal,mffile)
6831 endfor
6832 let i= i + 1
6833 endwhile
6834" call Dret("s:NetrwMarkFiles")
6835endfun
6836
6837" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006839fun! s:NetrwMarkTarget(...)
6840" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6841 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 let curdir = s:NetrwGetCurdir(1)
6843 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6846 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6851 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006852 let svpos = winsaveview()
6853" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006855" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6856 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006857" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006858endfun
6859
6860" ---------------------------------------------------------------------
6861" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6862" mark and unmark files. If a markfile list exists,
6863" then the rename and delete functions will use it instead
6864" of whatever may happen to be under the cursor at that
6865" moment. When the mouse and gui are available,
6866" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006867"
6868" Creates two lists
6869" s:netrwmarkfilelist -- holds complete paths to all marked files
6870" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6871"
6872" Creates a marked file match string
6873" s:netrwmarfilemtch_# -- used with 2match to display marked files
6874"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006875" Creates a buffer version of islocal
6876" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877fun! s:NetrwMarkFile(islocal,fname)
6878" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006879" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006880
6881 " sanity check
6882 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006883" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006884 return
6885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006886 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006887
Bram Moolenaar97d62492012-11-15 21:28:22 +01006888 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006890 if a:fname =~ '^\a'
6891 let leader= '\<'
6892 else
6893 let leader= ''
6894 endif
6895 if a:fname =~ '\a$'
6896 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6897 else
6898 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6899 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006902 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006903" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6904" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6905" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907
6908 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006909 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006912 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913
6914 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006915 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6918 if s:netrwmarkfilelist_{curbufnr} == []
6919 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 call s:NetrwUnmarkList(curbufnr,curdir)
6922 else
6923 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 for fname in s:netrwmarkfilelist_{curbufnr}
6928 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006929 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006931 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 endif
6933 let first= 0
6934 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 endif
6937 endif
6938
6939 else
6940 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6946" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947
6948 " build initial markfile matching pattern
6949 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006950 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006952 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 endif
6956
6957 " handle global markfilelist
6958 if exists("s:netrwmarkfilelist")
6959 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6960 if index(s:netrwmarkfilelist,dname) == -1
6961 " append new filename to global markfilelist
6962 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 else
6965 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6967" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006969" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006971" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972 unlet s:netrwmarkfilelist
6973 endif
6974 endif
6975 else
6976 " initialize new global-directory markfilelist
6977 let s:netrwmarkfilelist= []
6978 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
6981
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006982 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006983 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6984 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6985" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6986 if exists("g:did_drchip_netrwlist_syntax")
6987 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6988 endif
6989 else
6990" " call Decho("2match none",'~'.expand("<slnum>"))
6991 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006994 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006995" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6996" 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 +00006997endfun
6998
6999" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007000" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7001" mA: move the argument list to marked file list (tomflist=1)
7002" Uses the global marked file list
7003fun! s:NetrwMarkFileArgList(islocal,tomflist)
7004" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7005
7006 let svpos = winsaveview()
7007" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7008 let curdir = s:NetrwGetCurdir(a:islocal)
7009 let curbufnr = bufnr("%")
7010
7011 if a:tomflist
7012 " mA: move argument list to marked file list
7013 while argc()
7014 let fname= argv(0)
7015" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7016 exe "argdel ".fnameescape(fname)
7017 call s:NetrwMarkFile(a:islocal,fname)
7018 endwhile
7019
7020 else
7021 " ma: move marked file list to argument list
7022 if exists("s:netrwmarkfilelist")
7023
7024 " for every filename in the marked list
7025 for fname in s:netrwmarkfilelist
7026" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7027 exe "argadd ".fnameescape(fname)
7028 endfor " for every file in the marked list
7029
7030 " unmark list and refresh
7031 call s:NetrwUnmarkList(curbufnr,curdir)
7032 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7033" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7034 NetrwKeepj call winrestview(svpos)
7035 endif
7036 endif
7037
7038" call Dret("s:NetrwMarkFileArgList")
7039endfun
7040
7041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7043" compress/decompress files using the programs
7044" in g:netrw_compress and g:netrw_uncompress,
7045" using g:netrw_compress_suffix to know which to
7046" do. By default:
7047" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007048" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007049fun! s:NetrwMarkFileCompress(islocal)
7050" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007051 let svpos = winsaveview()
7052" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007054 let curbufnr = bufnr("%")
7055
Bram Moolenaarff034192013-04-24 18:51:19 +02007056 " sanity check
7057 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007058 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007059" call Dret("s:NetrwMarkFileCompress")
7060 return
7061 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007062" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007063
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007065
7066 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007070 if exists("g:netrw_decompress['".sfx."']")
7071 " fname has a suffix indicating that its compressed; apply associated decompression routine
7072 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007073" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007074 let exe= netrw#WinPath(exe)
7075 if a:islocal
7076 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007077 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 call system(exe." ".fname)
7080 if v:shell_error
7081 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007082 endif
7083 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7085 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007086 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007087
Bram Moolenaarff034192013-04-24 18:51:19 +02007088 endif
7089 unlet sfx
7090
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 if exists("exe")
7092 unlet exe
7093 elseif a:islocal
7094 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007095 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007096 if v:shell_error
7097 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 else
7100 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007101 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007103 endfor " for every file in the marked list
7104
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007107" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7108 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109 endif
7110" call Dret("s:NetrwMarkFileCompress")
7111endfun
7112
7113" ---------------------------------------------------------------------
7114" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7115" If no marked files, then set up directory as the
7116" target. Currently does not support copying entire
7117" directories. Uses the local-buffer marked file list.
7118" Returns 1=success (used by NetrwMarkFileMove())
7119" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007120fun! s:NetrwMarkFileCopy(islocal,...)
7121" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007123 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007124 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007125 if b:netrw_curdir !~ '/$'
7126 if !exists("b:netrw_curdir")
7127 let b:netrw_curdir= curdir
7128 endif
7129 let b:netrw_curdir= b:netrw_curdir."/"
7130 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131
Bram Moolenaarff034192013-04-24 18:51:19 +02007132 " sanity check
7133 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007134 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007135" call Dret("s:NetrwMarkFileCopy")
7136 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007138" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007139
Bram Moolenaar446cb832008-06-24 21:56:24 +00007140 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142" call Dret("s:NetrwMarkFileCopy 0")
7143 return 0
7144 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007146
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007147 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007148 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007150 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007151 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7152" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7153 return
7154 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155
7156 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007157 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007158 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7159 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007160" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007161 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7163 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007164" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007166 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007167 let oldname = a:1
7168 else
7169 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007170" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171 let s:recursive= 1
7172 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7173 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7174 if ret == 0
7175 break
7176 endif
7177 endfor
7178 unlet s:recursive
7179 call s:NetrwUnmarkList(curbufnr,curdir)
7180" call Dret("s:NetrwMarkFileCopy ".ret)
7181 return ret
7182 endif
7183
7184 call inputsave()
7185 let newname= input("Copy ".oldname." to : ",oldname,"file")
7186 call inputrestore()
7187 if newname == ""
7188" call Dret("s:NetrwMarkFileCopy 0")
7189 return 0
7190 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= s:ShellEscape(oldname)
7192 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7195 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007196 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007197 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007198 let args= substitute(args,'/','\\','g')
7199 let tgt = substitute(tgt, '/','\\','g')
7200 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007201 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7202 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7203 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7204 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7205" call Decho("args <".args.">",'~'.expand("<slnum>"))
7206" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207 if isdirectory(s:NetrwFile(args))
7208" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007211 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007212 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7213 " contents to a target. One must append the source directory name to the target to get xcopy to
7214 " do the right thing.
7215 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 endif
7218 else
7219 let copycmd= g:netrw_localcopycmd
7220 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 let copycmd = substitute(copycmd,'\s.*$','','')
7223 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 let copycmd = netrw#WinPath(copycmd).copycmdargs
7225 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007226 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007227 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007228" call Decho("args <".args.">",'~'.expand("<slnum>"))
7229" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7230" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7231" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007233 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007234 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007235 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 +01007236 else
7237 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7238 endif
7239" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007240 return 0
7241 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
7243 elseif a:islocal && !s:netrwmftgt_islocal
7244 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247
7248 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007249 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252
7253 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007254 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007256 let curdir = getcwd()
7257 let tmpdir = s:GetTempfile("")
7258 if tmpdir !~ '/'
7259 let tmpdir= curdir."/".tmpdir
7260 endif
7261 if exists("*mkdir")
7262 call mkdir(tmpdir)
7263 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007264 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 if v:shell_error != 0
7266 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 +01007267" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007268 return
7269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007272 if s:NetrwLcd(tmpdir)
7273" call Dret("s:NetrwMarkFileCopy : lcd failure")
7274 return
7275 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007277 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 if getcwd() == tmpdir
7280 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007283 if s:NetrwLcd(curdir)
7284" call Dret("s:NetrwMarkFileCopy : lcd failure")
7285 return
7286 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007287 if delete(tmpdir,"d")
7288 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007289 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007291 if s:NetrwLcd(curdir)
7292" call Dret("s:NetrwMarkFileCopy : lcd failure")
7293 return
7294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 endif
7296 endif
7297 endif
7298
7299 " -------
7300 " cleanup
7301 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007303 " remove markings from local buffer
7304 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007305" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7306" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7307" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7308" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7309" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7310" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7311 if exists("s:recursive")
7312" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7313 else
7314" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007315 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007317 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007319 else
7320 " refresh local and targets for fast browsing
7321 if !exists("s:recursive")
7322 " remove markings from local buffer
7323" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7324 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7325 endif
7326
7327 " refresh buffers
7328 if s:netrwmftgt_islocal
7329" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7330 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7331 endif
7332 if a:islocal && s:netrwmftgt != curdir
7333" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7334 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7335 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007336 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338" call Dret("s:NetrwMarkFileCopy 1")
7339 return 1
7340endfun
7341
7342" ---------------------------------------------------------------------
7343" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7344" invoke vim's diff mode on the marked files.
7345" Either two or three files can be so handled.
7346" Uses the global marked file list.
7347fun! s:NetrwMarkFileDiff(islocal)
7348" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7349 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350
Bram Moolenaarff034192013-04-24 18:51:19 +02007351 " sanity check
7352 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007353 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007354" call Dret("s:NetrwMarkFileDiff")
7355 return
7356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007357 let curdir= s:NetrwGetCurdir(a:islocal)
7358" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007359
Bram Moolenaara6878372014-03-22 21:02:50 +01007360 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 for fname in s:netrwmarkfilelist
7363 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007365" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367 diffthis
7368 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007369 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007370" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007371 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 diffthis
7373 else
7374 break
7375 endif
7376 endfor
7377 call s:NetrwUnmarkList(curbufnr,curdir)
7378 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007379
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380" call Dret("s:NetrwMarkFileDiff")
7381endfun
7382
7383" ---------------------------------------------------------------------
7384" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7385" Uses global markfilelist
7386fun! s:NetrwMarkFileEdit(islocal)
7387" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007391
7392 " sanity check
7393 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007395" call Dret("s:NetrwMarkFileEdit")
7396 return
7397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007399
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 if exists("s:netrwmarkfilelist_{curbufnr}")
7401 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007402 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 " unmark markedfile list
7404" call s:NetrwUnmarkList(curbufnr,curdir)
7405 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007406" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007407 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007409 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411" call Dret("s:NetrwMarkFileEdit")
7412endfun
7413
7414" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007415" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007416fun! s:NetrwMarkFileQFEL(islocal,qfel)
7417" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7418 call s:NetrwUnmarkAll()
7419 let curbufnr= bufnr("%")
7420
7421 if !empty(a:qfel)
7422 for entry in a:qfel
7423 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007425 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007427 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7428 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7429 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7430 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7433 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007434" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007435 endif
7436 endfor
7437 echo "(use me to edit marked files)"
7438 else
7439 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7440 endif
7441
7442" call Dret("s:NetrwMarkFileQFEL")
7443endfun
7444
7445" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7447" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7448" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7449fun! s:NetrwMarkFileExe(islocal,enbloc)
7450" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007451 let svpos = winsaveview()
7452" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007454 let curbufnr = bufnr("%")
7455
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007456 if a:enbloc == 0
7457 " individually apply command to files, one at a time
7458 " sanity check
7459 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7460 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7461" call Dret("s:NetrwMarkFileExe")
7462 return
7463 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 if exists("s:netrwmarkfilelist_{curbufnr}")
7467 " get the command
7468 call inputsave()
7469 let cmd= input("Enter command: ","","file")
7470 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007471" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 if cmd == ""
7473" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7474 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007475 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007476
7477 " apply command to marked files, individually. Substitute: filename -> %
7478 " If no %, then append a space and the filename to the command
7479 for fname in s:netrwmarkfilelist_{curbufnr}
7480 if a:islocal
7481 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007482 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 endif
7487 if cmd =~ '%'
7488 let xcmd= substitute(cmd,'%',fname,'g')
7489 else
7490 let xcmd= cmd.' '.fname
7491 endif
7492 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= system(xcmd)
7495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 let ret= s:RemoteSystem(xcmd)
7498 endif
7499 if v:shell_error < 0
7500 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7501 break
7502 else
7503 echo ret
7504 endif
7505 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506
7507 " unmark marked file list
7508 call s:NetrwUnmarkList(curbufnr,curdir)
7509
7510 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007512" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7513 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007517
7518 else " apply command to global list of files, en bloc
7519
7520 call inputsave()
7521 let cmd= input("Enter command: ","","file")
7522 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 if cmd == ""
7525" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7526 return
7527 endif
7528 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007531 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007532 endif
7533 if a:islocal
7534 call system(cmd)
7535 if v:shell_error < 0
7536 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7537 endif
7538 else
7539 let ret= s:RemoteSystem(cmd)
7540 endif
7541 call s:NetrwUnmarkAll()
7542
7543 " refresh the listing
7544 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007545" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7546 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547
7548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007549
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550" call Dret("s:NetrwMarkFileExe")
7551endfun
7552
7553" ---------------------------------------------------------------------
7554" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7555" as the marked file(s) (toggles suffix presence)
7556" Uses the local marked file list.
7557fun! s:NetrwMarkHideSfx(islocal)
7558" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007559 let svpos = winsaveview()
7560" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007561 let curbufnr = bufnr("%")
7562
7563 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7564 if exists("s:netrwmarkfilelist_{curbufnr}")
7565
7566 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007567" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007568 " construct suffix pattern
7569 if fname =~ '\.'
7570 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7571 else
7572 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7573 endif
7574 " determine if its in the hiding list or not
7575 let inhidelist= 0
7576 if g:netrw_list_hide != ""
7577 let itemnum = 0
7578 let hidelist= split(g:netrw_list_hide,',')
7579 for hidepat in hidelist
7580 if sfxpat == hidepat
7581 let inhidelist= 1
7582 break
7583 endif
7584 let itemnum= itemnum + 1
7585 endfor
7586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007587" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 if inhidelist
7589 " remove sfxpat from list
7590 call remove(hidelist,itemnum)
7591 let g:netrw_list_hide= join(hidelist,",")
7592 elseif g:netrw_list_hide != ""
7593 " append sfxpat to non-empty list
7594 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7595 else
7596 " set hiding list to sfxpat
7597 let g:netrw_list_hide= sfxpat
7598 endif
7599 endfor
7600
7601 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007602 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007606 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 endif
7608
7609" call Dret("s:NetrwMarkHideSfx")
7610endfun
7611
7612" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007614" Uses the local marked-file list.
7615fun! s:NetrwMarkFileVimCmd(islocal)
7616" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007617 let svpos = winsaveview()
7618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 let curbufnr = bufnr("%")
7621
Bram Moolenaarff034192013-04-24 18:51:19 +02007622 " sanity check
7623 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007624 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007625" call Dret("s:NetrwMarkFileVimCmd")
7626 return
7627 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007628" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007629
Bram Moolenaar15146672011-10-20 22:22:38 +02007630 if exists("s:netrwmarkfilelist_{curbufnr}")
7631 " get the command
7632 call inputsave()
7633 let cmd= input("Enter vim command: ","","file")
7634 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007636 if cmd == ""
7637" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7638 return
7639 endif
7640
7641 " apply command to marked files. Substitute: filename -> %
7642 " If no %, then append a space and the filename to the command
7643 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 if a:islocal
7646 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007647 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 exe cmd
7650 exe "sil! keepalt wq!"
7651 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007654 endif
7655 endfor
7656
7657 " unmark marked file list
7658 call s:NetrwUnmarkList(curbufnr,curdir)
7659
7660 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007661 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007662" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7663 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007664 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007665 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007667
Bram Moolenaar15146672011-10-20 22:22:38 +02007668" call Dret("s:NetrwMarkFileVimCmd")
7669endfun
7670
7671" ---------------------------------------------------------------------
7672" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7673" as the marked file(s) (toggles suffix presence)
7674" Uses the local marked file list.
7675fun! s:NetrwMarkHideSfx(islocal)
7676" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007677 let svpos = winsaveview()
7678" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 let curbufnr = bufnr("%")
7680
7681 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7682 if exists("s:netrwmarkfilelist_{curbufnr}")
7683
7684 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007686 " construct suffix pattern
7687 if fname =~ '\.'
7688 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7689 else
7690 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7691 endif
7692 " determine if its in the hiding list or not
7693 let inhidelist= 0
7694 if g:netrw_list_hide != ""
7695 let itemnum = 0
7696 let hidelist= split(g:netrw_list_hide,',')
7697 for hidepat in hidelist
7698 if sfxpat == hidepat
7699 let inhidelist= 1
7700 break
7701 endif
7702 let itemnum= itemnum + 1
7703 endfor
7704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007705" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007706 if inhidelist
7707 " remove sfxpat from list
7708 call remove(hidelist,itemnum)
7709 let g:netrw_list_hide= join(hidelist,",")
7710 elseif g:netrw_list_hide != ""
7711 " append sfxpat to non-empty list
7712 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7713 else
7714 " set hiding list to sfxpat
7715 let g:netrw_list_hide= sfxpat
7716 endif
7717 endfor
7718
7719 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007720 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007721" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7722 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007723 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007724 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007725 endif
7726
7727" call Dret("s:NetrwMarkHideSfx")
7728endfun
7729
7730" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007731" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7732" Uses the global markfilelist
7733fun! s:NetrwMarkFileGrep(islocal)
7734" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007735 let svpos = winsaveview()
7736" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007738 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739
7740 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007741" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007742 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007743" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007745 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007746" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 let netrwmarkfilelist= "*"
7748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007751" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 call inputsave()
7753 let pat= input("Enter pattern: ","")
7754 call inputrestore()
7755 let patbang = ""
7756 if pat =~ '^!'
7757 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007758 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007759 endif
7760 if pat =~ '^\i'
7761 let pat = escape(pat,'/')
7762 let pat = '/'.pat.'/'
7763 else
7764 let nonisi = pat[0]
7765 endif
7766
7767 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007769 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007770 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007771 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007772 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007773" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7774 return
7775 endtry
7776 echo "(use :cn, :cp to navigate, :Rex to return)"
7777
7778 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007779" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7780 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007781
7782 if exists("nonisi")
7783 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007784" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007785 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007788 endif
7789
7790" call Dret("s:NetrwMarkFileGrep")
7791endfun
7792
7793" ---------------------------------------------------------------------
7794" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7795" uses the global marked file list
7796" s:netrwmfloc= 0: target directory is remote
7797" = 1: target directory is local
7798fun! s:NetrwMarkFileMove(islocal)
7799" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 let curbufnr = bufnr("%")
7802
7803 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007804 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806" call Dret("s:NetrwMarkFileMove")
7807 return
7808 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007810
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007812 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813" call Dret("s:NetrwMarkFileCopy 0")
7814 return 0
7815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817
7818 if a:islocal && s:netrwmftgt_islocal
7819 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("move from local to local",'~'.expand("<slnum>"))
7821" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007822 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007823 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7824" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7825 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007829 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007830 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007832 if g:netrw_localmovecmd =~ '\s'
7833 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7834 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7835 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007838 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007840 endif
7841 else
7842 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007845 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007846 if g:netrw_keepdir
7847 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7848 let fname= b:netrw_curdir."/".fname
7849 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007850 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007851 let fname= substitute(fname,'/','\\','g')
7852 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858 else
7859 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7860 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007861 break
7862 endif
7863 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007864
7865 elseif a:islocal && !s:netrwmftgt_islocal
7866 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867" call Decho("move from local to remote",'~'.expand("<slnum>"))
7868" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007870 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872 for fname in mflist
7873 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7874 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7875 endfor
7876 unlet mflist
7877
7878 elseif !a:islocal && s:netrwmftgt_islocal
7879 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("move from remote to local",'~'.expand("<slnum>"))
7881" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885 for fname in mflist
7886 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7887 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7888 endfor
7889 unlet mflist
7890
7891 elseif !a:islocal && !s:netrwmftgt_islocal
7892 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7894" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 for fname in mflist
7899 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7900 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7901 endfor
7902 unlet mflist
7903 endif
7904
7905 " -------
7906 " cleanup
7907 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007908" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909
7910 " remove markings from local buffer
7911 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7912
7913 " refresh buffers
7914 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007915" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007916 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007917 endif
7918 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007920 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007924 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927" call Dret("s:NetrwMarkFileMove")
7928endfun
7929
7930" ---------------------------------------------------------------------
7931" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7932" using the hardcopy command. Local marked-file list only.
7933fun! s:NetrwMarkFilePrint(islocal)
7934" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7935 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007936
7937 " sanity check
7938 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007939 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007940" call Dret("s:NetrwMarkFilePrint")
7941 return
7942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7944 let curdir= s:NetrwGetCurdir(a:islocal)
7945
Bram Moolenaar446cb832008-06-24 21:56:24 +00007946 if exists("s:netrwmarkfilelist_{curbufnr}")
7947 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 call s:NetrwUnmarkList(curbufnr,curdir)
7949 for fname in netrwmarkfilelist
7950 if a:islocal
7951 if g:netrw_keepdir
7952 let fname= s:ComposePath(curdir,fname)
7953 endif
7954 else
7955 let fname= curdir.fname
7956 endif
7957 1split
7958 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007961" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 hardcopy
7963 q
7964 endfor
7965 2match none
7966 endif
7967" call Dret("s:NetrwMarkFilePrint")
7968endfun
7969
7970" ---------------------------------------------------------------------
7971" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7972" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007973" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007974fun! s:NetrwMarkFileRegexp(islocal)
7975" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7976
7977 " get the regular expression
7978 call inputsave()
7979 let regexp= input("Enter regexp: ","","file")
7980 call inputrestore()
7981
7982 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007984" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007987 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007988 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 else
7991 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007992 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007994" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995
7996 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007997 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007998 if fname =~ '^'.fnameescape(curdir)
7999" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8001 else
8002" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8003 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8004 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008005 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008008" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009
8010 " convert displayed listing into a filelist
8011 let eikeep = &ei
8012 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008013 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008014 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008018 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 sil NetrwKeepj norm! "ap
8020 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008023 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008029 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008031 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8032 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008033 call histdel("/",-1)
8034 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 endif
8036 " convert regexp into the more usual glob-style format
8037 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008038" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008040 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 let filelist= getline(1,line("$"))
8042 q!
8043 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 endfor
8046 unlet filelist
8047 let @a = areg
8048 let &ei = eikeep
8049 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008050 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051
8052" call Dret("s:NetrwMarkFileRegexp")
8053endfun
8054
8055" ---------------------------------------------------------------------
8056" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8057" Uses the local marked file list.
8058fun! s:NetrwMarkFileSource(islocal)
8059" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8060 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008061
8062 " sanity check
8063 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008065" call Dret("s:NetrwMarkFileSource")
8066 return
8067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8069 let curdir= s:NetrwGetCurdir(a:islocal)
8070
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 if exists("s:netrwmarkfilelist_{curbufnr}")
8072 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 call s:NetrwUnmarkList(curbufnr,curdir)
8074 for fname in netrwmarkfilelist
8075 if a:islocal
8076 if g:netrw_keepdir
8077 let fname= s:ComposePath(curdir,fname)
8078 endif
8079 else
8080 let fname= curdir.fname
8081 endif
8082 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008084 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085 endfor
8086 2match none
8087 endif
8088" call Dret("s:NetrwMarkFileSource")
8089endfun
8090
8091" ---------------------------------------------------------------------
8092" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8093" Uses the global markfilelist
8094fun! s:NetrwMarkFileTag(islocal)
8095" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008096 let svpos = winsaveview()
8097" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008099 let curbufnr = bufnr("%")
8100
Bram Moolenaarff034192013-04-24 18:51:19 +02008101 " sanity check
8102 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008103 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008104" call Dret("s:NetrwMarkFileTag")
8105 return
8106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008108
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8111 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 call s:NetrwUnmarkAll()
8113
8114 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008115
8116" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8117 call system(g:netrw_ctags." ".netrwmarkfilelist)
8118 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8120 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008121
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008123 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008124 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let curdir= b:netrw_curdir
8126 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008129" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008130 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008131 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 wq!
8133 endif
8134 2match none
8135 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008136" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8137 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 endif
8139
8140" call Dret("s:NetrwMarkFileTag")
8141endfun
8142
8143" ---------------------------------------------------------------------
8144" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008145" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008146" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008147" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008148" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008150" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8151 let svpos = winsaveview()
8152" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let hadtgt = exists("s:netrwmftgt")
8155 if !exists("w:netrw_bannercnt")
8156 let w:netrw_bannercnt= b:netrw_bannercnt
8157 endif
8158
8159 " set up target
8160 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8163 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 unlet s:netrwmftgt s:netrwmftgt_islocal
8166 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008167 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008168 endif
8169 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008170" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8171 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008172" call Dret("s:NetrwMarkFileTgt : removed target")
8173 return
8174 else
8175 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008177 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178
8179 else
8180 " get word under cursor.
8181 " * If directory, use it for the target.
8182 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let curword= s:NetrwGetWord()
8185 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 elseif !a:islocal && tgtdir =~ '/$'
8190 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 else
8193 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 endif
8196 endif
8197 if a:islocal
8198 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8199 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 endif
8202 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008204 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8205 endif
8206 let s:netrwmftgt_islocal= a:islocal
8207
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008208 " need to do refresh so that the banner will be updated
8209 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008210 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008211" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008212 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008215 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8217 else
8218 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8219 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008220" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8221 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008223 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
8225
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8227" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8229endfun
8230
8231" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8233fun! s:NetrwGetCurdir(islocal)
8234" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8235
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8239 elseif !exists("b:netrw_curdir")
8240 let b:netrw_curdir= getcwd()
8241" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8242 endif
8243
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245 if b:netrw_curdir !~ '\<\a\{3,}://'
8246 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008247" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008248 if g:netrw_keepdir == 0
8249 call s:NetrwLcd(curdir)
8250 endif
8251 endif
8252
8253" call Dret("s:NetrwGetCurdir <".curdir.">")
8254 return b:netrw_curdir
8255endfun
8256
8257" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008258" s:NetrwOpenFile: query user for a filename and open it {{{2
8259fun! s:NetrwOpenFile(islocal)
8260" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008261 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008262 call inputsave()
8263 let fname= input("Enter filename: ")
8264 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008265" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8266
8267 " determine if Lexplore is in use
8268 if exists("t:netrw_lexbufnr")
8269 " check if t:netrw_lexbufnr refers to a netrw window
8270" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8271 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8272 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8273" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8274 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8275 exe "NetrwKeepj e ".fnameescape(fname)
8276 let @@= ykeep
8277" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8278 endif
8279 endif
8280
8281 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008282 if fname !~ '[/\\]'
8283 if exists("b:netrw_curdir")
8284 if exists("g:netrw_quiet")
8285 let netrw_quiet_keep = g:netrw_quiet
8286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008287 let g:netrw_quiet = 1
8288 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008289 let s:rexposn_{bufnr("%")}= winsaveview()
8290" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008291 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008293 else
8294 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8295 endif
8296 if exists("netrw_quiet_keep")
8297 let g:netrw_quiet= netrw_quiet_keep
8298 else
8299 unlet g:netrw_quiet
8300 endif
8301 endif
8302 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008303 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008304 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008305 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008306" call Dret("s:NetrwOpenFile")
8307endfun
8308
8309" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008310" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8311" For the mapping to this function be made via
8312" netrwPlugin, you'll need to have had
8313" g:netrw_usetab set to non-zero.
8314fun! netrw#Shrink()
8315" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8316 let curwin = winnr()
8317 let wiwkeep = &wiw
8318 set wiw=1
8319
8320 if &ft == "netrw"
8321 if winwidth(0) > g:netrw_wiw
8322 let t:netrw_winwidth= winwidth(0)
8323 exe "vert resize ".g:netrw_wiw
8324 wincmd l
8325 if winnr() == curwin
8326 wincmd h
8327 endif
8328" call Decho("vert resize 0",'~'.expand("<slnum>"))
8329 else
8330 exe "vert resize ".t:netrw_winwidth
8331" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8332 endif
8333
8334 elseif exists("t:netrw_lexbufnr")
8335 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8336 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8337 let t:netrw_winwidth= winwidth(0)
8338 exe "vert resize ".g:netrw_wiw
8339 wincmd l
8340 if winnr() == curwin
8341 wincmd h
8342 endif
8343" call Decho("vert resize 0",'~'.expand("<slnum>"))
8344 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8345 exe "vert resize ".t:netrw_winwidth
8346" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8347 else
8348 call netrw#Lexplore(0,0)
8349 endif
8350
8351 else
8352 call netrw#Lexplore(0,0)
8353 endif
8354 let wiw= wiwkeep
8355
8356" call Dret("netrw#Shrink")
8357endfun
8358
8359" ---------------------------------------------------------------------
8360" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8361fun! s:NetSortSequence(islocal)
8362" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8363
8364 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008365 let svpos= winsaveview()
8366" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008367 call inputsave()
8368 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8369 call inputrestore()
8370
8371 " refresh the listing
8372 let g:netrw_sort_sequence= newsortseq
8373 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8375 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008376 let @@= ykeep
8377
8378" call Dret("NetSortSequence")
8379endfun
8380
8381" ---------------------------------------------------------------------
8382" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8383" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008384" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385fun! s:NetrwUnmarkList(curbufnr,curdir)
8386" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8387
8388 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8391 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8392 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8393 call remove(s:netrwmarkfilelist,idx) " remove from global list
8394 endfor
8395 if s:netrwmarkfilelist == []
8396 unlet s:netrwmarkfilelist
8397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008398
Bram Moolenaar446cb832008-06-24 21:56:24 +00008399 " getting rid of the local marked-file lists is easy
8400 unlet s:netrwmarkfilelist_{a:curbufnr}
8401 endif
8402 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8403 unlet s:netrwmarkfilemtch_{a:curbufnr}
8404 endif
8405 2match none
8406" call Dret("s:NetrwUnmarkList")
8407endfun
8408
8409" ---------------------------------------------------------------------
8410" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8411fun! s:NetrwUnmarkAll()
8412" call Dfunc("s:NetrwUnmarkAll()")
8413 if exists("s:netrwmarkfilelist")
8414 unlet s:netrwmarkfilelist
8415 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008416 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 2match none
8418" call Dret("s:NetrwUnmarkAll")
8419endfun
8420
8421" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008422" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423fun! s:NetrwUnmarkAll2()
8424" call Dfunc("s:NetrwUnmarkAll2()")
8425 redir => netrwmarkfilelist_let
8426 let
8427 redir END
8428 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8431 for flist in netrwmarkfilelist_list
8432 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8433 unlet s:netrwmarkfilelist_{curbufnr}
8434 unlet s:netrwmarkfilemtch_{curbufnr}
8435 endfor
8436" call Dret("s:NetrwUnmarkAll2")
8437endfun
8438
8439" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008440" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8441"
8442" Marked files are in two types of lists:
8443" s:netrwmarkfilelist -- holds complete paths to all marked files
8444" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8445"
8446" Marked files suitable for use with 2match are in:
8447" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448fun! s:NetrwUnMarkFile(islocal)
8449" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008450 let svpos = winsaveview()
8451" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 let curbufnr = bufnr("%")
8453
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454 " unmark marked file list
8455 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8456 if exists("s:netrwmarkfilelist")
8457" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 endif
8460
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461 let ibuf= 1
8462 while ibuf < bufnr("$")
8463 if exists("s:netrwmarkfilelist_".ibuf)
8464 unlet s:netrwmarkfilelist_{ibuf}
8465 unlet s:netrwmarkfilemtch_{ibuf}
8466 endif
8467 let ibuf = ibuf + 1
8468 endwhile
8469 2match none
8470
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008472"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8473call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008474" call Dret("s:NetrwUnMarkFile")
8475endfun
8476
8477" ---------------------------------------------------------------------
8478" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8479fun! s:NetrwMenu(domenu)
8480
8481 if !exists("g:NetrwMenuPriority")
8482 let g:NetrwMenuPriority= 80
8483 endif
8484
Bram Moolenaaradc21822011-04-01 18:03:16 +02008485 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8487
8488 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008491 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8495 if g:netrw_dirhistmax > 0
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8500 else
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8502 endif
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008518 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
Bram Moolenaarff034192013-04-24 18:51:19 +02008519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008555 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
Bram Moolenaarff034192013-04-24 18:51:19 +02008556 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008559 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8560 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561
8562 elseif !a:domenu
8563 let s:netrwcnt = 0
8564 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008565 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 exe curwin."wincmd w"
8567
8568 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008569" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008570 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008571" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008572 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 endif
8574 endif
8575" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008576 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 endif
8578
8579endfun
8580
8581" ---------------------------------------------------------------------
8582" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8583" Used by the O maps (as <SID>NetrwObtain())
8584fun! s:NetrwObtain(islocal)
8585" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8586
Bram Moolenaar97d62492012-11-15 21:28:22 +01008587 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008589 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008590 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8592 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008593 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008595 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596
8597" call Dret("NetrwObtain")
8598endfun
8599
8600" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8602" If there's only one window, then the window will first be split.
8603" Returns:
8604" choice = 0 : didn't have to choose
8605" choice = 1 : saved modified file in window first
8606" choice = 2 : didn't save modified file, opened window
8607" choice = 3 : cancel open
8608fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008609" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610
Bram Moolenaar97d62492012-11-15 21:28:22 +01008611 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008613 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615
8616 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008617 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8620" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8621 let curword = s:NetrwGetWord()
8622 let choice = 0
8623 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8624" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008625 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008626" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008627 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008628" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 if lastwinnr == 1
8634 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008636 " g:netrw_preview=0: preview window shown in a horizontally split window
8637 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008639 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008640 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008642 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008644 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008645 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008647 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008649 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651
8652 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008653" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008658 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#12: mod=".&mod)
8664
8665 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8666 " whoops -- user trying to open file in the Lexplore window.
8667 " Use Lexplore's opening-file window instead.
8668" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8669" exe g:netrw_chgwin."wincmd w"
8670 wincmd p
8671 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8672 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008673
8674 " prevwinnr: the window number of the "prev" window
8675 " prevbufnr: the buffer number of the buffer in the "prev" window
8676 " bnrcnt : the qty of windows open on the "prev" buffer
8677 let prevwinnr = winnr()
8678 let prevbufnr = bufnr("%")
8679 let prevbufname = bufname("%")
8680 let prevmod = &mod
8681 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008683 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008684" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008685" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686
8687 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008688 " and it doesn't appear in any other extant window, then ask the
8689 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008692 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008693" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008695" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696
8697 if bnrcnt == 1 && &hidden == 0
8698 " only one copy of the modified buffer in a window, and
8699 " hidden not set, so overwriting will lose the modified file. Ask first...
8700 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008701" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008703" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704
8705 if choice == 1
8706 " Yes -- write file & then browse
8707 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008708 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008710 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008711 exe origwin."wincmd w"
8712 let &ei = eikeep
8713 let @@ = ykeep
8714" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 return choice
8716 endif
8717
8718 elseif choice == 2
8719 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722
8723 else
8724 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008725" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008726 exe origwin."wincmd w"
8727 let &ei= eikeep
8728 let @@ = ykeep
8729" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 return choice
8731 endif
8732 endif
8733 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008734 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008736" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737
8738 " restore b:netrw_curdir (window split/enew may have lost it)
8739 let b:netrw_curdir= curdir
8740 if a:islocal < 2
8741 if a:islocal
8742 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8743 else
8744 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8745 endif
8746 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008747 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749 return choice
8750endfun
8751
8752" ---------------------------------------------------------------------
8753" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8754" Always assumed to be local -> remote
8755" call s:NetrwUpload(filename, target)
8756" call s:NetrwUpload(filename, target, fromdirectory)
8757fun! s:NetrwUpload(fname,tgt,...)
8758" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8759
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760 if a:tgt =~ '^\a\{3,}://'
8761 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 else
8763 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8764 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766
8767 if a:0 > 0
8768 let fromdir= a:1
8769 else
8770 let fromdir= getcwd()
8771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773
8774 if type(a:fname) == 1
8775 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8779 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8780" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 if a:tgt =~ '/$'
8782 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008784 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008787 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 endif
8790 q!
8791
8792 elseif type(a:fname) == 3
8793 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 let curdir= getcwd()
8796 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008797 if s:NetrwLcd(fromdir)
8798" call Dret("s:NetrwUpload : lcd failure")
8799 return
8800 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008801 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803 if exists("g:netrw_port") && g:netrw_port != ""
8804 let useport= " ".g:netrw_scpport." ".g:netrw_port
8805 else
8806 let useport= ""
8807 endif
8808 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8809 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008811 if s:NetrwLcd(curdir)
8812" call Dret("s:NetrwUpload : lcd failure")
8813 return
8814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815
8816 elseif a:tgt =~ '^ftp:'
8817 call s:NetrwMethod(a:tgt)
8818
8819 if b:netrw_method == 2
8820 " handle uploading a list of files via ftp+.netrc
8821 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008826" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827
8828 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
8832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835
Bram Moolenaaradc21822011-04-01 18:03:16 +02008836 if tgtdir == ""
8837 let tgtdir= '/'
8838 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841
8842 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8844" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 endfor
8846
8847 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008848 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8851 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 endif
8853 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008854 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008855 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8857 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8858 else
8859 bw!|q
8860 endif
8861
8862 elseif b:netrw_method == 3
8863 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8864 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008867 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008873 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008874" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875 endif
8876
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008877 if exists("g:netrw_uid") && g:netrw_uid != ""
8878 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008881 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008882 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889 endif
8890
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893
8894 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008896" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 endif
8898
8899 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
8904 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008906" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 endfor
8908
8909 " perform ftp:
8910 " -i : turns off interactive prompting from ftp
8911 " -n unix : DON'T use <.netrc>, even though it exists
8912 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008913 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008914 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008916 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008917 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8919 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008920 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8922 let &debug = debugkeep
8923 let mod = 1
8924 else
8925 bw!|q
8926 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008927 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008929 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 endif
8931 else
8932 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8933 endif
8934 endif
8935
8936" call Dret("s:NetrwUpload")
8937endfun
8938
8939" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941fun! s:NetrwPreview(path) range
8942" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8944" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008945 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946 NetrwKeepj call s:NetrwOptionsSave("s:")
8947 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8948 NetrwKeepj call s:NetrwOptionsSafe(1)
8949 else
8950 NetrwKeepj call s:NetrwOptionsSafe(0)
8951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008954 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8956 if g:netrw_preview
8957 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008958 let pvhkeep = &pvh
8959 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8960 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8962 else
8963 " horizontal split
8964 let pvhkeep = &pvh
8965 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8966 let &pvh = winheight(0) - winsz
8967" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008968 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969 " g:netrw_preview g:netrw_alto
8970 " 1 : vert 1: top -- preview window is vertically split off and on the left
8971 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8972 " 0 : 1: top -- preview window is horizontally split off and on the top
8973 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8974 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008975 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02008976 " the BufEnter event set up in netrwPlugin.vim
8977" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8978 let eikeep = &ei
8979 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008981 let &ei= eikeep
8982" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008983 if exists("pvhkeep")
8984 let &pvh= pvhkeep
8985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988 endif
8989 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008990 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008992 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008993 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994" call Dret("NetrwPreview")
8995endfun
8996
8997" ---------------------------------------------------------------------
8998" s:NetrwRefresh: {{{2
8999fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009000" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009002 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003" call Decho("setl ma noro",'~'.expand("<slnum>"))
9004" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009005 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009006 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9007 if !exists("w:netrw_treetop")
9008 if exists("b:netrw_curdir")
9009 let w:netrw_treetop= b:netrw_curdir
9010 else
9011 let w:netrw_treetop= getcwd()
9012 endif
9013 endif
9014 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9015 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009016
9017 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009018 let screenposn = winsaveview()
9019" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009020
9021" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9022" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9023 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009024 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009026 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009029
9030 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009031" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9032 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033
9034 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009035 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9036 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9037" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9038 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9039 else
9040" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9041 2match none
9042 endif
9043 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044
Bram Moolenaar97d62492012-11-15 21:28:22 +01009045" restore
9046 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009047" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048endfun
9049
9050" ---------------------------------------------------------------------
9051" s:NetrwRefreshDir: refreshes a directory by name {{{2
9052" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009053" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009055" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 if g:netrw_fastbrowse == 0
9057 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009058" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061
9062 if tgtwin > 0
9063 " tgtwin is being displayed, so refresh it
9064 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009067 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009068 exe curwin."wincmd w"
9069
9070 elseif bufnr(a:dirname) > 0
9071 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9073 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 endif
9075
9076 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009078 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 endif
9080" call Dret("s:NetrwRefreshDir")
9081endfun
9082
9083" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009084" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9085" window number to do its editing in.
9086" Supports [count]C where the count, if present, is used to specify
9087" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009089" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009090 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 if a:1 == "" " :NetrwC win#
9093 let g:netrw_chgwin= winnr()
9094 else " :NetrwC
9095 let g:netrw_chgwin= a:1
9096 endif
9097 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009098 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009100 let g:netrw_chgwin= winnr()
9101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009104endfun
9105
9106" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009107" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9108" What this function does is to compute a priority for the patterns
9109" in the g:netrw_sort_sequence. It applies a substitute to any
9110" "files" that satisfy each pattern, putting the priority / in
9111" front. An "*" pattern handles the default priority.
9112fun! s:NetrwSetSort()
9113" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009114 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 if w:netrw_liststyle == s:LONGLIST
9116 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9117 else
9118 let seqlist = g:netrw_sort_sequence
9119 endif
9120 " sanity check -- insure that * appears somewhere
9121 if seqlist == ""
9122 let seqlist= '*'
9123 elseif seqlist !~ '\*'
9124 let seqlist= seqlist.',*'
9125 endif
9126 let priority = 1
9127 while seqlist != ""
9128 if seqlist =~ ','
9129 let seq = substitute(seqlist,',.*$','','e')
9130 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9131 else
9132 let seq = seqlist
9133 let seqlist = ""
9134 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009135 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009136 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009138 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009139 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009140 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009142" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143
9144 " sanity check
9145 if w:netrw_bannercnt > line("$")
9146 " apparently no files were left after a Hiding pattern was used
9147" call Dret("SetSort : no files left after hiding")
9148 return
9149 endif
9150 if seq == '*'
9151 let starpriority= spriority
9152 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009153 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009154 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155 " sometimes multiple sorting patterns will match the same file or directory.
9156 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9158 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159 endif
9160 let priority = priority + 1
9161 endwhile
9162 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9164 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 endif
9166
9167 " Following line associated with priority -- items that satisfy a priority
9168 " pattern get prefixed by ###/ which permits easy sorting by priority.
9169 " Sometimes files can satisfy multiple priority patterns -- only the latest
9170 " priority pattern needs to be retained. So, at this point, these excess
9171 " priority prefixes need to be removed, but not directories that happen to
9172 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009173 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9174 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009175 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176
9177" call Dret("SetSort")
9178endfun
9179
Bram Moolenaarff034192013-04-24 18:51:19 +02009180" ---------------------------------------------------------------------
9181" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9182" Implements [count]Tb (bookhist<b>)
9183" [count]Th (bookhist<h>)
9184" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009185fun! s:NetrwSetTgt(islocal,bookhist,choice)
9186" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009187
9188 if a:bookhist == 'b'
9189 " supports choosing a bookmark as a target using a qb-generated list
9190 let choice= a:choice - 1
9191 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009192 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009193 else
9194 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9195 endif
9196
9197 elseif a:bookhist == 'h'
9198 " supports choosing a history stack entry as a target using a qb-generated list
9199 let choice= (a:choice % g:netrw_dirhistmax) + 1
9200 if exists("g:netrw_dirhist_".choice)
9201 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009202 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009203 else
9204 echomsg "Sorry, history#".a:choice." not available!"
9205 endif
9206 endif
9207
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009208 " refresh the display
9209 if !exists("b:netrw_curdir")
9210 let b:netrw_curdir= getcwd()
9211 endif
9212 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9213
Bram Moolenaarff034192013-04-24 18:51:19 +02009214" call Dret("s:NetrwSetTgt")
9215endfun
9216
Bram Moolenaar446cb832008-06-24 21:56:24 +00009217" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009218" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009219fun! s:NetrwSortStyle(islocal)
9220" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009221 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009222 let svpos= winsaveview()
9223" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009225 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009226 NetrwKeepj norm! 0
9227 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009228" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9229 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230
9231" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9232endfun
9233
9234" ---------------------------------------------------------------------
9235" s:NetrwSplit: mode {{{2
9236" =0 : net and o
9237" =1 : net and t
9238" =2 : net and v
9239" =3 : local and o
9240" =4 : local and t
9241" =5 : local and v
9242fun! s:NetrwSplit(mode)
9243" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9244
Bram Moolenaar97d62492012-11-15 21:28:22 +01009245 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 call s:SaveWinVars()
9247
9248 if a:mode == 0
9249 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009250 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009251 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009252" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009253 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj call s:RestoreWinVars()
9256 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257 unlet s:didsplit
9258
9259 elseif a:mode == 1
9260 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009261 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 tabnew
9264 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj call s:RestoreWinVars()
9266 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 unlet s:didsplit
9268
9269 elseif a:mode == 2
9270 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009271 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009272 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009274 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 3
9281 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009282 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009283 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009285 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj call s:RestoreWinVars()
9288 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289 unlet s:didsplit
9290
9291 elseif a:mode == 4
9292 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009294 let eikeep = &ei
9295 let netrw_winnr = winnr()
9296 let netrw_line = line(".")
9297 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009299 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009300 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009301 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9302 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009303 let &ei = eikeep
9304 let netrw_curdir = s:NetrwTreeDir(0)
9305" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009307 let b:netrw_curdir = netrw_curdir
9308 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj call s:RestoreWinVars()
9310 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009311 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009312 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009313 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9314 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009315 let &ei= eikeep
9316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317 unlet s:didsplit
9318
9319 elseif a:mode == 5
9320 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009321 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009322 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009323" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009324 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 NetrwKeepj call s:RestoreWinVars()
9327 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 unlet s:didsplit
9329
9330 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 endif
9333
Bram Moolenaar97d62492012-11-15 21:28:22 +01009334 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335" call Dret("s:NetrwSplit")
9336endfun
9337
9338" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009339" s:NetrwTgtMenu: {{{2
9340fun! s:NetrwTgtMenu()
9341 if !exists("s:netrw_menucnt")
9342 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009343 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009344" call Dfunc("s:NetrwTgtMenu()")
9345
9346 " the following test assures that gvim is running, has menus available, and has menus enabled.
9347 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9348 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009349" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009350 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9351 endif
9352 if !exists("s:netrw_initbookhist")
9353 call s:NetrwBookHistRead()
9354 endif
9355
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356 " try to cull duplicate entries
9357 let tgtdict={}
9358
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 " target bookmarked places
9360 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009362 let cnt= 1
9363 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364 if has_key(tgtdict,bmd)
9365 let cnt= cnt + 1
9366 continue
9367 endif
9368 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 let ebmd= escape(bmd,g:netrw_menu_escape)
9370 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009372 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009373 let cnt= cnt + 1
9374 endfor
9375 endif
9376
9377 " target directory browsing history
9378 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 let histcnt = 1
9381 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009382 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009383 if exists("g:netrw_dirhist_{histcnt}")
9384 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 if has_key(tgtdict,histentry)
9386 let histcnt = histcnt + 1
9387 continue
9388 endif
9389 let tgtdict[histentry] = histcnt
9390 let ehistentry = escape(histentry,g:netrw_menu_escape)
9391" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009392 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009393 endif
9394 let histcnt = histcnt + 1
9395 endwhile
9396 endif
9397 endif
9398" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399endfun
9400
9401" ---------------------------------------------------------------------
9402" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9403" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009404fun! s:NetrwTreeDir(islocal)
9405" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009406" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009407" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9408" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9409" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009410" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009411
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009412 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009413 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009415 let treedir= s:treedir
9416 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009417 unlet s:prevwinopen
9418" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009419 return treedir
9420 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421 if exists("s:prevwinopen")
9422 unlet s:prevwinopen
9423 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009424" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425
Bram Moolenaar8d043172014-01-23 14:24:41 +01009426 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9427 let b:netrw_curdir= getcwd()
9428 endif
9429 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433 let s:treecurpos= winsaveview()
9434" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009436
9437 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9439" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009440" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009441
9442 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009443 let curline= substitute(getline('.'),"\t -->.*$",'','')
9444 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009447" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9448 elseif curline =~ '@$'
9449" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009450 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 let treedir= ""
9455 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009456" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457
9458 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9460" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009461" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009462 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9466 sil! NetrwKeepj %d _
9467" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009469" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009470" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009471 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009472" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009475" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009476" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009477
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9479" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9480" let newdir = w:netrw_treetop.'/'.potentialdir
9481" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9482" let treedir = s:NetrwTreePath(newdir)
9483" let w:netrw_treetop = newdir
9484" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9485" else
9486" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009487 if a:islocal && curline =~ '@$'
9488 if isdirectory(s:NetrwFile(potentialdir))
9489 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9490 let w:netrw_treetop = treedir
9491 endif
9492 else
9493 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9494 let treedir = s:NetrwTreePath(w:netrw_treetop)
9495 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009496 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009497" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009498
9499 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009502" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009504" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009505 return treedir
9506endfun
9507
9508" ---------------------------------------------------------------------
9509" s:NetrwTreeDisplay: recursive tree display {{{2
9510fun! s:NetrwTreeDisplay(dir,depth)
9511" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9512
9513 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009514 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515
9516 " install ../ and shortdir
9517 if a:depth == ""
9518 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009519" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 if a:dir == w:netrw_treetop
9523 let shortdir= a:dir
9524 else
9525 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9526 endif
9527 call setline(line("$")+1,a:depth.shortdir)
9528 else
9529 let shortdir= substitute(a:dir,'^.*/','','e')
9530 call setline(line("$")+1,a:depth.shortdir.'/')
9531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 " append a / to dir if its missing one
9534 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535
9536 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009537 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539
Bram Moolenaar85850f32019-07-19 22:05:51 +02009540 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9541 if g:netrw_hide == 1
9542 " hide given patterns
9543 let listhide= split(g:netrw_list_hide,',')
9544" call Decho("listhide=".string(listhide))
9545 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009546 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009547 endfor
9548
9549 elseif g:netrw_hide == 2
9550 " show given patterns (only)
9551 let listhide= split(g:netrw_list_hide,',')
9552" call Decho("listhide=".string(listhide))
9553 let entries=[]
9554 for entry in w:netrw_treedict[dir]
9555 for pat in listhide
9556 if entry =~ pat
9557 call add(entries,entry)
9558 break
9559 endif
9560 endfor
9561 endfor
9562 let w:netrw_treedict[dir]= entries
9563 endif
9564 if depth != ""
9565 " always remove "." and ".." entries when there's depth
9566 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9567 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9568 endif
9569
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009570" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009572 if dir =~ '/$'
9573 let direntry= substitute(dir.entry,'[@/]$','','e')
9574 else
9575 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009580 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9584 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9585" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009589 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 endif
9591 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009592" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009593
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594" call Dret("NetrwTreeDisplay")
9595endfun
9596
9597" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009598" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9599fun! s:NetrwRefreshTreeDict(dir)
9600" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009601 if !exists("w:netrw_treedict")
9602" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9603 return
9604 endif
9605
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 for entry in w:netrw_treedict[a:dir]
9607 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9608" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9609
9610 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9611" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9612 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009613 let liststar = s:NetrwGlob(direntry,'*',1)
9614 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009615 let w:netrw_treedict[direntry] = liststar + listdotstar
9616" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9617
9618 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9619" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9620 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009621 let liststar = s:NetrwGlob(direntry.'/','*',1)
9622 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009623 let w:netrw_treedict[direntry]= liststar + listdotstar
9624" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9625
9626 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9627" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9628 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009629 let liststar = s:NetrwGlob(direntry.'/','*',1)
9630 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009631" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9632
9633 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009634" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635 endif
9636 endfor
9637" call Dret("s:NetrwRefreshTreeDict")
9638endfun
9639
9640" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009642" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009643fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009645" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009646" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9647" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
9648" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009649
9650 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009652" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009654 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009657" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009662 if exists("w:netrw_treetop")
9663 let s:netrw_treetop= w:netrw_treetop
9664 else
9665 let w:netrw_treetop= getcwd()
9666 let s:netrw_treetop= w:netrw_treetop
9667 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009670 " insure that we have a treedict, albeit empty
9671" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 let w:netrw_treedict= {}
9673 endif
9674
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 " update the dictionary for the current directory
9676" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009681 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682
9683 " if past banner, record word
9684 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9685 let fname= expand("<cword>")
9686 else
9687 let fname= ""
9688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9690" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691
9692 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009693" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009696
9697 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9698 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009700 1d
9701 endwhile
9702
Bram Moolenaar13600302014-05-22 18:26:40 +02009703 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009705" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009706 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707 endif
9708endfun
9709
9710" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009711" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009712" Normally, treetop is w:netrw_treetop, but a
9713" user of the function ( netrw#SetTreetop() )
9714" wipes that out prior to calling this function
9715fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009716" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9717 if line(".") < w:netrw_bannercnt + 2
9718 let treedir= a:treetop
9719 if treedir !~ '/$'
9720 let treedir= treedir.'/'
9721 endif
9722" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9723 return treedir
9724 endif
9725
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009726 let svpos = winsaveview()
9727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009728 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009730 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9732 let curline= getline('.')
9733" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9734 if curline =~ '/$'
9735" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9736 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9737" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9738 elseif curline =~ '@\s\+-->'
9739" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9740 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9741 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9742" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 let treedir= ""
9746 endif
9747 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9749" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9751 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9752 let treedir= dirname.treedir
9753 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009756" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 if a:treetop =~ '/$'
9758 let treedir= a:treetop.treedir
9759 else
9760 let treedir= a:treetop.'/'.treedir
9761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009762" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009764" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009765" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9766 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009767" call Dret("s:NetrwTreePath <".treedir.">")
9768 return treedir
9769endfun
9770
9771" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772" s:NetrwWideListing: {{{2
9773fun! s:NetrwWideListing()
9774
9775 if w:netrw_liststyle == s:WIDELIST
9776" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9777 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009778 " cpf: characters per filename
9779 " fpl: filenames per line
9780 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009781 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009782 let dict={}
9783 " save the unnamed register and register 0-9 and a
9784 let dict.a=[getreg('a'), getregtype('a')]
9785 for i in range(0, 9)
9786 let dict[i] = [getreg(i), getregtype(i)]
9787 endfor
9788 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009789" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790 let b:netrw_cpf= 0
9791 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009792 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009793 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9794 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009796 " restore stored registers
9797 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798" call Dret("NetrwWideListing")
9799 return
9800 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009801 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009802 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804
9805 " determine qty files per line (fpl)
9806 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9807 if w:netrw_fpl <= 0
9808 let w:netrw_fpl= 1
9809 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811
9812 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813 " fpc: files per column of wide listing
9814 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009815 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9817 let newcolstart = w:netrw_bannercnt + fpc
9818 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009820 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009821" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009822 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009823 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825 while line("$") >= newcolstart
9826 if newcolend > line("$") | let newcolend= line("$") | endif
9827 let newcolqty= newcolend - newcolstart
9828 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009829 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009831 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009833 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009835 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009836 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009838 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009839" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009840 if @* != keepregstar | sil! let @* = keepregstar | endif
9841 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009842 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009843 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9844 NetrwKeepj call histdel("/",-1)
9845 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9846 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009847" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009848 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009849 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009850" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009851" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009852 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009853 else
9854 if hasmapto("w","n")
9855 sil! nunmap <buffer> w
9856 endif
9857 if hasmapto("b","n")
9858 sil! nunmap <buffer> b
9859 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861endfun
9862
9863" ---------------------------------------------------------------------
9864" s:PerformListing: {{{2
9865fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009866" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9867" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009868" call Decho("settings: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)"." ei<".&ei.">",'~'.expand("<slnum>"))
9869 sil! NetrwKeepj %d _
9870" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871
Bram Moolenaar15146672011-10-20 22:22:38 +02009872 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009875
Bram Moolenaar85850f32019-07-19 22:05:51 +02009876 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009877 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879
9880" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009881" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882" endif " Decho
9883
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9886 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9888 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889 endif
9890
9891 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009892 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893
9894 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009895 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009897 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898 if exists("g:netrw_pchk")
9899 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9900 " failure detections.
9901 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9904 endif
9905 if exists("g:netrw_pchk")
9906 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9907 else
9908 let curdir= b:netrw_curdir
9909 endif
9910 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9911 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9912 else
9913 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009914 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009915 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009916 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009917 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009920 let w:netrw_bannercnt= 1
9921 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9923" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009924
Bram Moolenaar85850f32019-07-19 22:05:51 +02009925 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009927 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009928 let sortby= sortby." reversed"
9929 endif
9930
9931 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009932 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009934 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009936 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 NetrwKeepj put ='\" Sorted by '.sortby
9938 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009939 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009942 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9945 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009947" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950
Bram Moolenaar85850f32019-07-19 22:05:51 +02009951 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009952 if g:netrw_banner
9953 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009957 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009958 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009960 endif
9961 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009962 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009965 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967
9968 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009970" call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 if g:netrw_list_hide != "" && g:netrw_hide
9972 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009973 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009974 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 endif
9977 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009980
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009982 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009988" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991
9992 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009993 if g:netrw_banner
9994 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("--w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009997" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009999 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010004 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010007 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010009" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10010 return
10011 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
10014 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010015 if !exists("w:netrw_bannercnt")
10016 let w:netrw_bannercnt= 0
10017 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10019" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10020" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010021
Bram Moolenaar5c736222010-01-06 20:54:52 +010010022 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010023" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010024" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010025 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010026 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010028 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010031 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010033" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035
Bram Moolenaar5c736222010-01-06 20:54:52 +010010036 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010038 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010039 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 else
10042 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 endif
10045 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010046
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10050 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010052 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010053 " exten: sort by extension
10054 " The histdel(...,-1) calls remove the last search from the search history
10055" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10057 NetrwKeepj call histdel("/",-1)
10058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10059 NetrwKeepj call histdel("/",-1)
10060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10061 NetrwKeepj call histdel("/",-1)
10062 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10063" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010064 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065 " normal direction sorting
10066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10067 else
10068 " reverse direction sorting
10069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10070 endif
10071 endif
10072 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10073 NetrwKeepj call histdel("/",-1)
10074
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010076 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010078 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010084 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010085" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010086 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10087 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010088 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010089 endif
10090
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010091 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010093 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010094 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010095 call histdel("/",-1)
10096 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010097 endif
10098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010100
10101 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10103" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010104 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010106 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010108
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010110 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010112 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 endif
10114
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010116 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10118 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10121 else
10122" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10123" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10124" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10125" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126 endif
10127
10128 " record previous current directory
10129 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131
10132 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10134" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#4)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010135 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010137 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010139
10140 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010142 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010144 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010146 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10147 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010148" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010149" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010150
Bram Moolenaar8d043172014-01-23 14:24:41 +010010151 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10153" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#8)",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010154" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10155 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156 unlet s:treecurpos
10157 endif
10158
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)",'~'.expand("<slnum>"))
10160" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010161" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10162endfun
10163
10164" ---------------------------------------------------------------------
10165" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010166fun! s:SetupNetrwStatusLine(statline)
10167" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10168
10169 if !exists("s:netrw_setup_statline")
10170 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010171" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010172
10173 if !exists("s:netrw_users_stl")
10174 let s:netrw_users_stl= &stl
10175 endif
10176 if !exists("s:netrw_users_ls")
10177 let s:netrw_users_ls= &laststatus
10178 endif
10179
10180 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010181 let dict={}
10182 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010183 redir @a
10184 try
10185 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187 if &bg == "dark"
10188 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10189 else
10190 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10191 endif
10192 endtry
10193 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010194 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010195 endif
10196
10197 " set up status line (may use User9 highlighting)
10198 " insure that windows have a statusline
10199 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010200 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010201 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010202" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010204
10205" call Dret("SetupNetrwStatusLine : stl=".&stl)
10206endfun
10207
Bram Moolenaar85850f32019-07-19 22:05:51 +020010208" =========================================
10209" Remote Directory Browsing Support: {{{1
10210" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010211
10212" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010213" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10214" This function assumes that a long listing will be received. Size, time,
10215" and reverse sorts will be requested of the server but not otherwise
10216" enforced here.
10217fun! s:NetrwRemoteFtpCmd(path,listcmd)
10218" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) w:netrw_method=".(exists("w:netrw_method")? w:netrw_method : (exists("b:netrw_method")? b:netrw_method : "???")))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010219" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010220 " sanity check: {{{3
10221 if !exists("w:netrw_method")
10222 if exists("b:netrw_method")
10223 let w:netrw_method= b:netrw_method
10224 else
10225 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10226" call Dret("NetrwRemoteFtpCmd")
10227 return
10228 endif
10229 endif
10230
10231 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10232 let ffkeep= &ff
10233 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010234" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010235
10236 " clear off any older non-banner lines " {{{3
10237 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010238" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10239 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010240
10241 ".........................................
10242 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10243 " ftp + <.netrc>: Method #2
10244 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010246 endif
10247 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010248 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010251 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010252" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10255 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010256 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10258 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 endif
10260
10261 ".........................................
10262 elseif w:netrw_method == 3 " {{{3
10263 " ftp + machine,id,passwd,filename: Method #3
10264 setl ff=unix
10265 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010266 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 endif
10270
10271 " handle userid and password
10272 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010273" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10275 call NetUserPass("ftp:".host)
10276 endif
10277 if exists("g:netrw_uid") && g:netrw_uid != ""
10278 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
10283 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 endif
10286 endif
10287
10288 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
10291 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010293" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010296
10297 " perform ftp:
10298 " -i : turns off interactive prompting from ftp
10299 " -n unix : DON'T use <.netrc>, even though it exists
10300 " -n win32: quit being obnoxious about password
10301 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010302" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010304" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010305" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10306" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 endif
10308
10309 ".........................................
10310 elseif w:netrw_method == 9 " {{{3
10311 " sftp username@machine: Method #9
10312 " s:netrw_sftp_cmd
10313 setl ff=unix
10314
10315 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010316 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010317" call Dret("NetrwRemoteFtpCmd")
10318 return
10319
10320 ".........................................
10321 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010322 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010323 endif
10324
10325 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010326 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010327 sil! NetrwKeepj %s/\r$//e
10328 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
10330 if a:listcmd == "dir"
10331 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10333 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10334 NetrwKeepj call histdel("/",-1)
10335 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010336 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010337 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10338 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 endif
10340 endif
10341
10342 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10343 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010344 exe 'NetrwKeepj '.w:netrw_bannercnt
10345 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 endif
10347 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010348 exe 'NetrwKeepj '.w:netrw_bannercnt
10349 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 endif
10351
10352 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010353 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010354" call Dret("NetrwRemoteFtpCmd")
10355endfun
10356
10357" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358" s:NetrwRemoteListing: {{{2
10359fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010360" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010361
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10363 let w:netrw_bannercnt= s:bannercnt
10364 endif
10365 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010366 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010367 endif
10368
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010370
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371 " sanity check:
10372 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010373" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010375" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 if !exists("g:netrw_quiet")
10377 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10378 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010379 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010380" call Dret("s:NetrwRemoteListing -1")
10381 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010382 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383
Bram Moolenaar8d043172014-01-23 14:24:41 +010010384 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010387 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010388 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your g:netrw_list_cmd is empty; perhaps ".g:netrw_ssh_cmd." is not executable on your system",47)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010390 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010392 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010393
Bram Moolenaar85850f32019-07-19 22:05:51 +020010394 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010395" call Dret("s:NetrwRemoteListing -1")
10396 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010399
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 let w:netrw_method= b:netrw_method
10403 endif
10404
Bram Moolenaar13600302014-05-22 18:26:40 +020010405 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010406 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010407" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010408 let s:method = "ftp"
10409 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010410 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010412 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 let listcmd= g:netrw_ftp_sizelist_cmd
10414 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418
Bram Moolenaara6878372014-03-22 21:02:50 +010010419 " report on missing file or directory messages
10420 if search('[Nn]o such file or directory\|Failed to change directory')
10421 let mesg= getline(".")
10422 if exists("w:netrw_bannercnt")
10423 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010424 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 setl noma
10426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010427 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010428 call netrw#ErrorMsg(s:WARNING,mesg,96)
10429" call Dret("s:NetrwRemoteListing : -1")
10430 return -1
10431 endif
10432
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010433 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010435" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437
10438 " cleanup
10439 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10441 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 sil! NetrwKeepj %s/\r$//e
10444 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010446 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010449 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010452" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 exe "sil! NetrwKeepj ".line1
10456 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10462 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10466 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10467 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10468 NetrwKeepj call histdel("/",-1)
10469 NetrwKeepj call histdel("/",-1)
10470 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471 endif
10472 endif
10473
Bram Moolenaar13600302014-05-22 18:26:40 +020010474 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10481 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010483 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10484 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10485 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10486 NetrwKeepj call histdel("/",-1)
10487 NetrwKeepj call histdel("/",-1)
10488 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010490 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10491 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492 endif
10493 else
10494 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10499 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10500" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 endif
10502 endif
10503
10504 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010505 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010507 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10508 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 endif
10510 endif
10511
10512 if w:netrw_liststyle == s:LONGLIST
10513 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010514" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515
10516 if s:method == "ftp"
10517 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010518 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010519 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010522 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 sil! NetrwKeepj 1
10525 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526 let line2= line(".")
10527 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 endif
10531 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010532 exe "sil! NetrwKeepj ".line1
10533 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 endif
10535
10536 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010540" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010541 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010542 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10544 NetrwKeepj call histdel("/",-1)
10545 NetrwKeepj call histdel("/",-1)
10546 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547 endif
10548 endif
10549
10550" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010553
10554" call Dret("s:NetrwRemoteListing 0")
10555 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010556endfun
10557
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558" ---------------------------------------------------------------------
10559" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10560fun! s:NetrwRemoteRm(usrhost,path) range
10561" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010563 let svpos= winsaveview()
10564" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565
10566 let all= 0
10567 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10568 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010569" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 for fname in s:netrwmarkfilelist_{bufnr("%")}
10571 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010572 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010574 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 let all= 1
10576 endif
10577 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010578 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
10580 else
10581 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583
10584 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585 let keepsol = &l:sol
10586 setl nosol
10587 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588
10589 " remove multiple files and directories
10590 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010591 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010593 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010595 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 let all= 1
10597 endif
10598 let ctr= ctr + 1
10599 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 endif
10602
10603 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010605 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010606" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10607 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608
10609" call Dret("s:NetrwRemoteRm")
10610endfun
10611
10612" ---------------------------------------------------------------------
10613" s:NetrwRemoteRmFile: {{{2
10614fun! s:NetrwRemoteRmFile(path,rmfile,all)
10615" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10616
10617 let all= a:all
10618 let ok = ""
10619
10620 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10621 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 if !all
10624 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010626 call inputsave()
10627 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10628 call inputrestore()
10629 echohl NONE
10630 if ok == ""
10631 let ok="no"
10632 endif
10633 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010634 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 let all= 1
10636 endif
10637 endif
10638
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010639 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010641 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644 if path =~ '^\a\{3,}://'
10645 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010647 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10649 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010654 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 let ok="q"
10656 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010657 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10659" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10660" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 if v:shell_error != 0
10669 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010670 call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671 else
10672 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10673 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010674 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 endif
10679 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010680 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 endif
10683
10684 else
10685 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 if !all
10688 call inputsave()
10689 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10690 call inputrestore()
10691 if ok == ""
10692 let ok="no"
10693 endif
10694 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010695 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 let all= 1
10697 endif
10698 endif
10699
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010700 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010702 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 else
10704 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10706" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010707 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709
10710 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10712 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10713" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010714 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010715" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716
10717 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010718 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 endif
10720 endif
10721 endif
10722
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010723 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010724" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725 endif
10726 endif
10727
10728" call Dret("s:NetrwRemoteRmFile ".ok)
10729 return ok
10730endfun
10731
10732" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733" s:NetrwRemoteRename: rename a remote file or directory {{{2
10734fun! s:NetrwRemoteRename(usrhost,path) range
10735" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10736
10737 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010738 let svpos = winsaveview()
10739" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740 let ctr = a:firstline
10741 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10742
10743 " rename files given by the markfilelist
10744 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10745 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 if exists("subfrom")
10748 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 else
10751 call inputsave()
10752 let newname= input("Moving ".oldname." to : ",oldname)
10753 call inputrestore()
10754 if newname =~ '^s/'
10755 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10756 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10757 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759 endif
10760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010761
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010763 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765 let oldname= s:ShellEscape(a:path.oldname)
10766 let newname= s:ShellEscape(a:path.newname)
10767" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010768 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 endif
10770
10771 endfor
10772 call s:NetrwUnMarkFile(1)
10773
10774 else
10775
10776 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010777 let keepsol= &l:sol
10778 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010779 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010780 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781
10782 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010783" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784
10785 call inputsave()
10786 let newname= input("Moving ".oldname." to : ",oldname)
10787 call inputrestore()
10788
10789 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10790 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10791 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792 let oldname= s:ShellEscape(a:path.oldname)
10793 let newname= s:ShellEscape(a:path.newname)
10794" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010795 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010796 endif
10797
10798 let ctr= ctr + 1
10799 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010800 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010801 endif
10802
10803 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010804 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010805" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10806 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807
10808" call Dret("NetrwRemoteRename")
10809endfun
10810
Bram Moolenaar85850f32019-07-19 22:05:51 +020010811" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812" Local Directory Browsing Support: {{{1
10813" ==========================================
10814
10815" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010816" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010817" Should accept: file://localhost/etc/fstab
10818" file:///etc/fstab
10819" file:///c:/WINDOWS/clock.avi
10820" file:///c|/WINDOWS/clock.avi
10821" file://localhost/c:/WINDOWS/clock.avi
10822" file://localhost/c|/WINDOWS/clock.avi
10823" file://c:/foo.txt
10824" file:///c:/foo.txt
10825" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaar85850f32019-07-19 22:05:51 +020010826fun! netrw#FileUrlEdit(fname)
10827" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 let fname = a:fname
10829 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010830" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010834 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010837 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 endif
10840 endif
10841 let fname2396 = netrw#RFC2396(fname)
10842 let fname2396e= fnameescape(fname2396)
10843 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010844 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010845" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10849 endif
10850 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010851
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10853" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010855 exe 'NetrwKeepj keepalt edit '.plainfname
10856 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10857
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010859" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 exe "sil doau BufReadPost ".fname2396e
10861endfun
10862
10863" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010864" netrw#LocalBrowseCheck: {{{2
10865fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010866 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010867 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10868 "
10869 " unfortunate interaction -- split window debugging can't be used here, must use
10870 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10871 " another call to LocalBrowseCheck() when attempts to write
10872 " to the DBG buffer are made.
10873 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 " The &ft == "netrw" test was installed because the BufEnter event
10875 " would hit when re-entering netrw windows, creating unexpected
10876 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010878" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010880 " getting E930: Cannot use :redir inside execute
10881"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010882" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10883" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010884
Bram Moolenaar97d62492012-11-15 21:28:22 +010010885 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886 if isdirectory(s:NetrwFile(a:dirname))
10887" call Decho("is-directory ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")." ft<".&ft."> g:netrw_fastbrowse=".g:netrw_fastbrowse,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010888
Bram Moolenaar97d62492012-11-15 21:28:22 +010010889 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10891" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010892 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010893
Bram Moolenaar446cb832008-06-24 21:56:24 +000010894 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010896 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010897
Bram Moolenaar5c736222010-01-06 20:54:52 +010010898 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010900 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010901 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010904" call Dret("netrw#LocalBrowseCheck")
10905 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010907
Bram Moolenaar85850f32019-07-19 22:05:51 +020010908 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010909 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10910 " AND IF the listing style is not a tree listing
10911 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010913 let ibuf = 1
10914 let buflast = bufnr("$")
10915 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10917 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010918 endif
10919 let ibuf= ibuf + 1
10920 endwhile
10921 endif
10922 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
10924" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010925 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010926" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927endfun
10928
10929" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010930" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010931" performed any shell command. The idea is to cause all local-browsing
10932" buffers to be refreshed after a user has executed some shell command,
10933" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010934fun! s:LocalBrowseRefresh()
10935" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10937" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010938
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 " determine which buffers currently reside in a tab
10940 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010941" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010942 return
10943 endif
10944 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010945" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 return
10947 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010948 if !empty(getcmdwintype())
10949 " cannot move away from cmdline window, see :h E11
10950 return
10951 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010952 if exists("s:netrw_events") && s:netrw_events == 1
10953 " s:LocalFastBrowser gets called (indirectly) from a
10954 let s:netrw_events= 2
10955" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10956 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 let itab = 1
10959 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010960 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010961 while itab <= tabpagenr("$")
10962 let buftablist = buftablist + tabpagebuflist()
10963 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010964 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10967" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10969 " | refresh any netrw window
10970 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010971 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 let ibl = 0
10973 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10976 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010977 " (ibuf not shown in a current window AND
10978 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10980 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 continue
10984 elseif index(tabpagebuflist(),ibuf) != -1
10985 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010988 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010989 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10990 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10991 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10992 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010994 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10995 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10996 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010997 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 endif
10999 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011001 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011002" call Decho("restore window: win_gotoid(".curwinid.")")
11003 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011004 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005
Bram Moolenaara6878372014-03-22 21:02:50 +010011006" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011007endfun
11008
11009" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011010" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11011"
11012" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11015" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017"
11018" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11019" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011020" (re-using a buffer may not be as accurate)
11021"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011022" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011023" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11024" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11025" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11026" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011028" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11029" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11030" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11031" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032
11033 " initialize browselist, a list of buffer numbers that the local browser has used
11034 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011035" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036 let s:netrw_browselist= []
11037 endif
11038
11039 " append current buffer to fastbrowse list
11040 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011041" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011042 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 endif
11045
11046 " enable autocmd events to handle refreshing/removing local browser buffers
11047 " If local browse buffer is currently showing: refresh it
11048 " If local browse buffer is currently hidden : wipe it
11049 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11050 " =1 : medium speed, re-use directory listing for remote only
11051 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011052 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11053 let s:netrw_events= 1
11054 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011056 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011060" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011062 endif
11063 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064
11065 " user must have changed fastbrowse to its fast setting, so remove
11066 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011067 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011069 unlet s:netrw_events
11070 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071 au!
11072 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074 endif
11075
Bram Moolenaar85850f32019-07-19 22:05:51 +020011076" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011077endfun
11078
11079" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011080" s:LocalListing: does the job of "ls" for local directories {{{2
11081fun! s:LocalListing()
11082" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11084" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11085" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011086
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
11088" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist",'~'.expand("<slnum>"))|endif
11089" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011090
11091 " get the list of files contained in the current directory
11092 let dirname = b:netrw_curdir
11093 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011094 let filelist = s:NetrwGlob(dirname,"*",0)
11095 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011097
Nir Lichtman1e34b952024-05-08 19:19:34 +020011098 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11101 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011103 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 endif
11106
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011107" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011109" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110
11111 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11112 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11113 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11115" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011118
11119 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120" call Decho(" ",'~'.expand("<slnum>"))
11121" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122
11123 if getftype(filename) == "link"
11124 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 let pfile= filename."@"
11127
11128 elseif getftype(filename) == "socket"
11129 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 let pfile= filename."="
11132
11133 elseif getftype(filename) == "fifo"
11134 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."|"
11137
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011138 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."/"
11142
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011144 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11146 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 let pfile= filename."*"
11149 else
11150 " normal file
11151 let pfile= filename
11152 endif
11153 elseif executable(filename)
11154 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011156 let pfile= filename."*"
11157 else
11158 " normal file
11159 let pfile= filename
11160 endif
11161
11162 else
11163 " normal file
11164 let pfile= filename
11165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011166" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011167
11168 if pfile =~ '//$'
11169 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011170" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171 endif
11172 let pfile= strpart(pfile,dirnamelen)
11173 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011174" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11175" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011176
11177 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011178 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11179 let sz = getfsize(filename)
11180 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11181 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011182
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011183 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011184 let sz= s:NetrwHumanReadable(sz)
11185 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011186 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011187 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011188" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 endif
11190
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011191 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011192 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011193 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011194" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011195" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011197 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011198" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011200 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011201
11202 elseif g:netrw_sort_by =~ "^s"
11203 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011207 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011208" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011210 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011211
11212 else
11213 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011214" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011216 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011217 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011218" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 endfor
11220
11221 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011222 sil! NetrwKeepj g/^$/d
11223 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011225" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011226 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11227
11228" call Dret("s:LocalListing")
11229endfun
11230
11231" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011232" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11233fun! s:NetrwLocalExecute(cmd)
11234" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11235 let ykeep= @@
11236 " sanity check
11237 if !executable(a:cmd)
11238 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11239 let @@= ykeep
11240" call Dret("s:NetrwLocalExecute")
11241 return
11242 endif
11243
11244 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011245" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011246 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011247" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011248
11249 " strip any ansi escape sequences off
11250 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11251
11252 " show user the result(s)
11253 echomsg result
11254 let @@= ykeep
11255
11256" call Dret("s:NetrwLocalExecute")
11257endfun
11258
11259" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011260" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261fun! s:NetrwLocalRename(path) range
11262" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11263
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011264 if !exists("w:netrw_bannercnt")
11265 let w:netrw_bannercnt= b:netrw_bannercnt
11266 endif
11267
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011269 let ykeep = @@
11270 let ctr = a:firstline
11271 let svpos = winsaveview()
11272 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011273" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274
11275 " rename files given by the markfilelist
11276 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11277 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011278" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 if exists("subfrom")
11280 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011281" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 else
11283 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011284 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011286 if newname =~ ''
11287 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11288 let newname = substitute(newname,'^.*','','')
11289 elseif newname =~ ''
11290 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11291 let newname = substitute(newname,'[^/]*','','')
11292 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 if newname =~ '^s/'
11294 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11295 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011296" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011297 let newname = substitute(oldname,subfrom,subto,'')
11298 endif
11299 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011300 if !all && filereadable(newname)
11301 call inputsave()
11302 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11303 call inputrestore()
11304 if response == "all"
11305 let all= 1
11306 elseif response != "y" && response != "yes"
11307 " refresh the directory
11308" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11309 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11310" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11311 NetrwKeepj call winrestview(svpos)
11312 let @@= ykeep
11313" call Dret("NetrwLocalRename")
11314 return
11315 endif
11316 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011317 call rename(oldname,newname)
11318 endfor
11319 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011320
Bram Moolenaar97d62492012-11-15 21:28:22 +010011321 else
11322
11323 " attempt to rename files/directories
11324 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011325 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011326
11327 " sanity checks
11328 if line(".") < w:netrw_bannercnt
11329 let ctr= ctr + 1
11330 continue
11331 endif
11332 let curword= s:NetrwGetWord()
11333 if curword == "./" || curword == "../"
11334 let ctr= ctr + 1
11335 continue
11336 endif
11337
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011338 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011339 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011340" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011341
11342 call inputsave()
11343 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11344 call inputrestore()
11345
11346 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011347" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348
11349 let ctr= ctr + 1
11350 endwhile
11351 endif
11352
11353 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011354" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011355 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011356" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11357 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011358 let @@= ykeep
11359
11360" call Dret("NetrwLocalRename")
11361endfun
11362
11363" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364" s:NetrwLocalRm: {{{2
11365fun! s:NetrwLocalRm(path) range
11366" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011367" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011368
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011369 if !exists("w:netrw_bannercnt")
11370 let w:netrw_bannercnt= b:netrw_bannercnt
11371 endif
11372
Bram Moolenaar446cb832008-06-24 21:56:24 +000011373 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011374 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375 let ret = 0
11376 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011377 let svpos = winsaveview()
11378" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379
11380 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11381 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011382" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 for fname in s:netrwmarkfilelist_{bufnr("%")}
11384 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011385 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011387 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011388 let all= 1
11389 endif
11390 endfor
11391 call s:NetrwUnMarkFile(1)
11392
11393 else
11394 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011397 let keepsol= &l:sol
11398 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 let ctr = a:firstline
11400 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011401 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011402
11403 " sanity checks
11404 if line(".") < w:netrw_bannercnt
11405 let ctr= ctr + 1
11406 continue
11407 endif
11408 let curword= s:NetrwGetWord()
11409 if curword == "./" || curword == "../"
11410 let ctr= ctr + 1
11411 continue
11412 endif
11413 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011414 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011415 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011416 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011417 let all= 1
11418 endif
11419 let ctr= ctr + 1
11420 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011421 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 endif
11423
11424 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011425" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011427 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011428" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11429 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011431 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432
11433" call Dret("s:NetrwLocalRm")
11434endfun
11435
11436" ---------------------------------------------------------------------
11437" s:NetrwLocalRmFile: remove file fname given the path {{{2
11438" Give confirmation prompt unless all==1
11439fun! s:NetrwLocalRmFile(path,fname,all)
11440" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011441
Bram Moolenaar446cb832008-06-24 21:56:24 +000011442 let all= a:all
11443 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011444 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011445 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011447
11448 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11449 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011451 if !all
11452 echohl Statement
11453 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011454 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455 call inputrestore()
11456 echohl NONE
11457 if ok == ""
11458 let ok="no"
11459 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011460" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011462" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011463 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011464 let all= 1
11465 endif
11466 endif
11467
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011468 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011469 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011470" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011471 endif
11472
11473 else
11474 " attempt to remove directory
11475 if !all
11476 echohl Statement
11477 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011478 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011479 call inputrestore()
11480 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11481 if ok == ""
11482 let ok="no"
11483 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011484 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011485 let all= 1
11486 endif
11487 endif
11488 let rmfile= substitute(rmfile,'[\/]$','','e')
11489
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011490 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011491 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011492 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011493 endif
11494 endif
11495 endif
11496
11497" call Dret("s:NetrwLocalRmFile ".ok)
11498 return ok
11499endfun
11500
Bram Moolenaar85850f32019-07-19 22:05:51 +020011501" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011502" Support Functions: {{{1
11503
Bram Moolenaar488c6512005-08-11 20:09:58 +000011504" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011505" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11506" 0: marked file list of current buffer
11507" 1: marked file target
11508fun! netrw#Access(ilist)
11509 if a:ilist == 0
11510 if exists("s:netrwmarkfilelist_".bufnr('%'))
11511 return s:netrwmarkfilelist_{bufnr('%')}
11512 else
11513 return "no-list-buf#".bufnr('%')
11514 endif
11515 elseif a:ilist == 1
11516 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011517 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011518endfun
11519
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011520" ---------------------------------------------------------------------
11521" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11522fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011523 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524endfun
11525
Bram Moolenaara6878372014-03-22 21:02:50 +010011526" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011527" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11528" I expect this function to be used in
11529" :PChkAssert netrw#Expose("netrwmarkfilelist")
11530" for example.
11531fun! netrw#Expose(varname)
11532" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011533 if exists("s:".a:varname)
11534 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011535" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011536 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011537" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011538 if type(retval) == 3
11539 let retval = copy(retval)
11540 let i = 0
11541 while i < len(retval)
11542 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11543 let i = i + 1
11544 endwhile
11545 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011546" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011547 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011548 else
11549" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011550 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011551 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011552" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011553 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011554 endif
11555
11556" call Dret("netrw#Expose ".string(retval))
11557 return retval
11558endfun
11559
11560" ---------------------------------------------------------------------
11561" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11562fun! netrw#Modify(varname,newvalue)
11563" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11564 exe "let s:".a:varname."= ".string(a:newvalue)
11565" call Dret("netrw#Modify")
11566endfun
11567
11568" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011569" netrw#RFC2396: converts %xx into characters {{{2
11570fun! netrw#RFC2396(fname)
11571" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011572 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011573" call Dret("netrw#RFC2396 ".fname)
11574 return fname
11575endfun
11576
11577" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011578" netrw#UserMaps: supports user-specified maps {{{2
11579" see :help function()
11580"
11581" g:Netrw_UserMaps is a List with members such as:
11582" [[keymap sequence, function reference],...]
11583"
11584" The referenced function may return a string,
11585" refresh : refresh the display
11586" -other- : this string will be executed
11587" or it may return a List of strings.
11588"
11589" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011590" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591" Related functions:
11592" netrw#Expose(varname) -- see s:varname variables
11593" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11594" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11595fun! netrw#UserMaps(islocal)
11596" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11597" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11598
11599 " set up usermaplist
11600 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11601" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11602 for umap in g:Netrw_UserMaps
11603" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11604" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11605 " if umap[0] is a string and umap[1] is a string holding a function name
11606 if type(umap[0]) == 1 && type(umap[1]) == 1
11607" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11608 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11609 else
11610 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11611 endif
11612 endfor
11613 endif
11614" call Dret("netrw#UserMaps")
11615endfun
11616
11617" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011618" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11619fun! netrw#WinPath(path)
11620" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011621 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011622 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011623 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011624 " remove trailing slash (Win95)
11625 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11626 " remove escaped spaces
11627 let path = substitute(path, '\ ', ' ', 'g')
11628 " convert slashes to backslashes
11629 let path = substitute(path, '/', '\', 'g')
11630 else
11631 let path= a:path
11632 endif
11633" call Dret("netrw#WinPath <".path.">")
11634 return path
11635endfun
11636
11637" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011638" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11639fun! s:StripTrailingSlash(path)
11640 " remove trailing slash
11641 return substitute(a:path, '[/\\]$', '', 'g')
11642endfun
11643
Travis Sheltone34d0e32024-07-30 21:08:56 +020011644" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011645" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11646" cb : bl2mf=0 add marked files to buffer list
11647" cB : bl2mf=1 use bufferlist to mark files
11648" (mnemonic: cb = copy (marked files) to buffer list)
11649fun! s:NetrwBadd(islocal,bl2mf)
11650" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11651 if a:bl2mf
11652 " cB: add buffer list to marked files
11653 redir => bufl
11654 ls
11655 redir END
11656 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11657 for fname in bufl
11658 call s:NetrwMarkFile(a:islocal,fname)
11659 endfor
11660 else
11661 " cb: add marked files to buffer list
11662 for fname in s:netrwmarkfilelist_{bufnr("%")}
11663" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11664 exe "badd ".fnameescape(fname)
11665 endfor
11666 let curbufnr = bufnr("%")
11667 let curdir = s:NetrwGetCurdir(a:islocal)
11668 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11669 endif
11670" call Dret("s:NetrwBadd")
11671endfun
11672
11673" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011674" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11675fun! s:ComposePath(base,subdir)
11676" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11677
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011678 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011679" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011680 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011681 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011682 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011683 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011684 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011685 endif
11686
Bram Moolenaar85850f32019-07-19 22:05:51 +020011687 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011688 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011689" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690 let ret= a:subdir
11691
Nir Lichtman1e34b952024-05-08 19:19:34 +020011692 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011694 if a:base =~ '[/\\]$'
11695 let ret= a:base.a:subdir
11696 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011698 endif
11699
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700 elseif a:base =~ '^\a\{3,}://'
11701" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011702 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11703 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11704 if a:subdir == '../'
11705 if curpath =~ '[^/]/[^/]\+/$'
11706 let curpath= substitute(curpath,'[^/]\+/$','','')
11707 else
11708 let curpath=""
11709 endif
11710 let ret= urlbase.curpath
11711 else
11712 let ret= urlbase.curpath.a:subdir
11713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011714" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11715" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11716" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011717
11718 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011720 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11721 if a:base =~ '^//'
11722 " keeping initial '//' for the benefit of network share listing support
11723 let ret= '/'.ret
11724 endif
11725 let ret= simplify(ret)
11726 endif
11727
11728" call Dret("s:ComposePath ".ret)
11729 return ret
11730endfun
11731
11732" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011733" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11734" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11735fun! s:DeleteBookmark(fname)
11736" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11737 call s:MergeBookmarks()
11738
11739 if exists("g:netrw_bookmarklist")
11740 let indx= index(g:netrw_bookmarklist,a:fname)
11741 if indx == -1
11742 let indx= 0
11743 while indx < len(g:netrw_bookmarklist)
11744 if g:netrw_bookmarklist[indx] =~ a:fname
11745 call remove(g:netrw_bookmarklist,indx)
11746 let indx= indx - 1
11747 endif
11748 let indx= indx + 1
11749 endwhile
11750 else
11751 " remove exact match
11752 call remove(g:netrw_bookmarklist,indx)
11753 endif
11754 endif
11755
11756" call Dret("s:DeleteBookmark")
11757endfun
11758
11759" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011760" s:FileReadable: o/s independent filereadable {{{2
11761fun! s:FileReadable(fname)
11762" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11763
11764 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011767 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011768 endif
11769
11770" call Dret("s:FileReadable ".ret)
11771 return ret
11772endfun
11773
11774" ---------------------------------------------------------------------
11775" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11776" Places correct suffix on end of temporary filename,
11777" using the suffix provided with fname
11778fun! s:GetTempfile(fname)
11779" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11780
11781 if !exists("b:netrw_tmpfile")
11782 " get a brand new temporary filename
11783 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011785
Bram Moolenaarc236c162008-07-13 17:41:49 +000011786 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788
Bram Moolenaar9964e462007-05-05 17:54:07 +000011789 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011790 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11791" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011792 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793" call Dret("s:GetTempfile getcwd<".getcwd().">")
11794 return ""
11795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011796
Bram Moolenaar9964e462007-05-05 17:54:07 +000011797 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011798 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011803 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011804 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805 if !exists("+shellslash") || !&ssl
11806 let tmpfile = substitute(tmpfile,'/','\','g')
11807 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 endif
11811 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011812" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 else
11814 " re-use temporary filename
11815 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 endif
11818
11819 " use fname's suffix for the temporary file
11820 if a:fname != ""
11821 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011823 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011825 elseif a:fname =~ '.txz$'
11826 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 else
11828 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11829 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11836 endif
11837 endif
11838
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011839" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840" call Dret("s:GetTempfile <".tmpfile.">")
11841 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011842endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011843
11844" ---------------------------------------------------------------------
11845" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011846" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011848" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011849 if s:user == ""
11850 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11851 else
11852 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11853 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011855 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011856 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011857 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011858 else
11859 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11860 endif
11861" call Dret("s:MakeSshCmd <".sshcmd.">")
11862 return sshcmd
11863endfun
11864
11865" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011866" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11867fun! s:MakeBookmark(fname)
11868" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11869
11870 if !exists("g:netrw_bookmarklist")
11871 let g:netrw_bookmarklist= []
11872 endif
11873
11874 if index(g:netrw_bookmarklist,a:fname) == -1
11875 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011876 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011877 call add(g:netrw_bookmarklist,a:fname.'/')
11878 elseif a:fname !~ '/'
11879 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11880 else
11881 call add(g:netrw_bookmarklist,a:fname)
11882 endif
11883 call sort(g:netrw_bookmarklist)
11884 endif
11885
11886" call Dret("s:MakeBookmark")
11887endfun
11888
11889" ---------------------------------------------------------------------
11890" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11891fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011893 " get bookmarks from .netrwbook file
11894 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895 if filereadable(s:NetrwFile(savefile))
11896" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011898" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011899 NetrwKeepj call delete(savefile)
11900 endif
11901" call Dret("s:MergeBookmarks")
11902endfun
11903
11904" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011905" s:NetrwBMShow: {{{2
11906fun! s:NetrwBMShow()
11907" call Dfunc("s:NetrwBMShow()")
11908 redir => bmshowraw
11909 menu
11910 redir END
11911 let bmshowlist = split(bmshowraw,'\n')
11912 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011913 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011914 if bmshowfuncs != []
11915 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011916 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011917 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011919 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011920 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11922endfun
11923
11924" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011925" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011926fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011927 if !exists("w:netrw_liststyle")
11928 let w:netrw_liststyle= g:netrw_liststyle
11929 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011930" call Dfunc("s:NetrwCursor() ft<".&ft."> liststyle=".w:netrw_liststyle." g:netrw_cursor=".g:netrw_cursor." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011932" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11933
Bram Moolenaaradc21822011-04-01 18:03:16 +020011934 if &ft != "netrw"
11935 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11936 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011937" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011939 elseif g:netrw_cursor == 8
11940 if w:netrw_liststyle == s:WIDELIST
11941 setl cursorline
11942 setl cursorcolumn
11943 else
11944 setl cursorline
11945 endif
11946 elseif g:netrw_cursor == 7
11947 setl cursorline
11948 elseif g:netrw_cursor == 6
11949 if w:netrw_liststyle == s:WIDELIST
11950 setl cursorline
11951 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011952 elseif g:netrw_cursor == 4
11953 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011955 setl cursorline
11956 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957
11958 elseif g:netrw_cursor == 3
11959 " thin-long-tree: cursorline, user's cursorcolumn
11960 " wide : cursorline, cursorcolumn
11961 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011963 setl cursorline
11964 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011967 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 endif
11969
11970 elseif g:netrw_cursor == 2
11971 " thin-long-tree: cursorline, user's cursorcolumn
11972 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011974 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975
11976 elseif g:netrw_cursor == 1
11977 " thin-long-tree: user's cursorline, user's cursorcolumn
11978 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011981 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011983" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011984 endif
11985
11986 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011988" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989 let &l:cursorline = s:netrw_usercul
11990 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011991 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011992
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011993" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011995endfun
11996
11997" ---------------------------------------------------------------------
11998" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11999fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012000" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001 if exists("s:netrw_usercul")
12002 let &l:cursorline = s:netrw_usercul
12003 endif
12004 if exists("s:netrw_usercuc")
12005 let &l:cursorcolumn = s:netrw_usercuc
12006 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012007" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012008" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12009endfun
12010
Christian Brabandt62f7b552024-06-23 20:23:40 +020012011" s:RestoreRegister: restores all registers given in the dict {{{2
12012fun! s:RestoreRegister(dict)
12013 for [key, val] in items(a:dict)
12014 if key == 'unnamed'
12015 let key = ''
12016 endif
12017 call setreg(key, val[0], val[1])
12018 endfor
12019endfun
12020
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012021" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012022" s:NetrwDelete: Deletes a file. {{{2
12023" Uses Steve Hall's idea to insure that Windows paths stay
12024" acceptable. No effect on Unix paths.
12025" Examples of use: let result= s:NetrwDelete(path)
12026fun! s:NetrwDelete(path)
12027" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12028
Bram Moolenaar5c736222010-01-06 20:54:52 +010012029 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012030 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031 if exists("+shellslash")
12032 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012033 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012034 let result = delete(path)
12035 let &shellslash = sskeep
12036 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012037" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012038 let result= delete(path)
12039 endif
12040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012041" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012042 let result= delete(path)
12043 endif
12044 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012045 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012046 endif
12047
12048" call Dret("s:NetrwDelete ".result)
12049 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012050endfun
12051
12052" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012053" s:NetrwBufRemover: removes a buffer that: {{{2s
12054" has buffer-id > 1
12055" is unlisted
12056" is unnamed
12057" does not appear in any window
12058fun! s:NetrwBufRemover(bufid)
12059" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12060" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12061" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12062" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12063" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12064
yasuda4dbb2662023-10-04 20:50:35 +020012065 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012066" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012067 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012068 endif
12069
12070" call Dret("s:NetrwBufRemover")
12071endfun
12072
12073" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012074" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012075fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012076" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012077" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012078
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012079 " Clean out the last buffer:
12080 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12081 " If so, delete it.
12082 call s:NetrwBufRemover(bufnr("$"))
12083
Bram Moolenaar446cb832008-06-24 21:56:24 +000012084 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012085" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012086 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12087 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12088 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12089 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12090 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12091 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12092 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12093 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12094 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12095 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12096 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12097 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12098 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12099 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12100 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12101 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12102
Bram Moolenaar85850f32019-07-19 22:05:51 +020012103 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012104" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012105 " when tree listing uses file TreeListing... a new buffer is made.
12106 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012107 " COMBAK: this causes a problem, see P43
12108" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012109 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012110 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012111 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012112" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012113 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012114
Bram Moolenaar446cb832008-06-24 21:56:24 +000012115 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012116" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012117 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12118 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12119 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12120 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12121 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12122 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12123 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12124 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12125 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12126 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12127 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12128 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12129 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12130 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12131 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12132 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12133
Bram Moolenaar5c736222010-01-06 20:54:52 +010012134 if a:0 > 0
12135 let b:netrw_curdir= a:1
12136 if b:netrw_curdir =~ '/$'
12137 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012138 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012139 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012140 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012141 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12142 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012143 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012144 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012145 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012146 endif
12147 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012148 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12149 let &l:bexpr = "netrw#BalloonHelp()"
12150 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012151
Bram Moolenaar8d043172014-01-23 14:24:41 +010012152" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012153endfun
12154
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012155" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012156" s:NetrwExe: executes a string using "!" {{{2
12157fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012158" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012159 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012160" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012161 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12162 set shell& shellcmdflag& shellxquote& shellxescape&
12163 set shellquote& shellpipe& shellredir& shellslash&
12164 exe a:cmd
12165 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12166 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012167" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012168 exe a:cmd
12169 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012170 if v:shell_error
12171 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12172 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012173" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012174endfun
12175
12176" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012177" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12178fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012179 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012180" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012181 let curbuf = bufnr("%")
12182 let curwin = winnr()
12183 let iwin = 1
12184 while iwin <= winnr("$")
12185 exe iwin."wincmd w"
12186 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12187 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12188 let winvars= w:
12189 break
12190 endif
12191 let iwin= iwin + 1
12192 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012193 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012194 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012195" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012196 for k in keys(winvars)
12197 let w:{k}= winvars[k]
12198 endfor
12199 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012200" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012201 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012202endfun
12203
Bram Moolenaara6878372014-03-22 21:02:50 +010012204" ---------------------------------------------------------------------
12205" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012206" Returns: 0=success
12207" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012208fun! s:NetrwLcd(newdir)
12209" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012210" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012211
Bram Moolenaar85850f32019-07-19 22:05:51 +020012212 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012213 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012214 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012215 catch /^Vim\%((\a\+)\)\=:E344/
12216 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12217 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012218 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12220 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012221 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12223 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012224 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012225 endif
12226 endif
12227 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012228 let err472= 1
12229 endtry
12230
12231 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012232 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12233 if exists("w:netrw_prvdir")
12234 let a:newdir= w:netrw_prvdir
12235 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012236 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012237" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012238 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012239" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012240 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012242" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12243 return -1
12244 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012245
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012246" call Decho("getcwd <".getcwd().">")
12247" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012248" call Dret("s:NetrwLcd 0")
12249 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012250endfun
12251
Bram Moolenaar9964e462007-05-05 17:54:07 +000012252" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012253" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12254" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12255fun! s:NetrwSaveWordPosn()
12256" call Dfunc("NetrwSaveWordPosn()")
12257 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12258" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12259endfun
12260
12261" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012262" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12263" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12264fun! s:NetrwHumanReadable(sz)
12265" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12266
12267 if g:netrw_sizestyle == 'h'
12268 if a:sz >= 1000000000
12269 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12270 elseif a:sz >= 10000000
12271 let sz = printf("%d",a:sz/1000000)."m"
12272 elseif a:sz >= 1000000
12273 let sz = printf("%.1f",a:sz/1000000.0)."m"
12274 elseif a:sz >= 10000
12275 let sz = printf("%d",a:sz/1000)."k"
12276 elseif a:sz >= 1000
12277 let sz = printf("%.1f",a:sz/1000.0)."k"
12278 else
12279 let sz= a:sz
12280 endif
12281
12282 elseif g:netrw_sizestyle == 'H'
12283 if a:sz >= 1073741824
12284 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12285 elseif a:sz >= 10485760
12286 let sz = printf("%d",a:sz/1048576)."M"
12287 elseif a:sz >= 1048576
12288 let sz = printf("%.1f",a:sz/1048576.0)."M"
12289 elseif a:sz >= 10240
12290 let sz = printf("%d",a:sz/1024)."K"
12291 elseif a:sz >= 1024
12292 let sz = printf("%.1f",a:sz/1024.0)."K"
12293 else
12294 let sz= a:sz
12295 endif
12296
12297 else
12298 let sz= a:sz
12299 endif
12300
12301" call Dret("s:NetrwHumanReadable ".sz)
12302 return sz
12303endfun
12304
12305" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012306" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12307" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12308fun! s:NetrwRestoreWordPosn()
12309" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012310 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012311" call Dret("NetrwRestoreWordPosn")
12312endfun
12313
12314" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012315" s:RestoreBufVars: {{{2
12316fun! s:RestoreBufVars()
12317" call Dfunc("s:RestoreBufVars()")
12318
12319 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12320 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12321 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12322 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12323 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12324 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12325
12326" call Dret("s:RestoreBufVars")
12327endfun
12328
12329" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012330" s:RemotePathAnalysis: {{{2
12331fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012332" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012333
Bram Moolenaara6878372014-03-22 21:02:50 +010012334 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012335 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012336 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012337 let s:user = substitute(a:dirname,dirpat,'\3','')
12338 let s:machine = substitute(a:dirname,dirpat,'\4','')
12339 let s:port = substitute(a:dirname,dirpat,'\5','')
12340 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012341 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012342 if s:machine =~ '@'
12343 let dirpat = '^\(.*\)@\(.\{-}\)$'
12344 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12345 let s:machine = substitute(s:machine,dirpat,'\2','')
12346 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012347
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012348" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12349" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12350" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12351" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12352" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12353" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012354
12355" call Dret("s:RemotePathAnalysis")
12356endfun
12357
12358" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012359" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12360" Returns status
12361" Runs system() on
12362" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012363" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012364fun! s:RemoteSystem(cmd)
12365" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12366 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012367 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012368 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012369 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012370 else
12371 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12372 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12373 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012374 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012375 else
12376 let cmd= cmd.' '
12377 endif
12378 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012380 let ret= system(cmd)
12381 endif
12382" call Dret("s:RemoteSystem ".ret)
12383 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012384endfun
12385
12386" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012387" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388fun! s:RestoreWinVars()
12389" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012390 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012391 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12392 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12393 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12394 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12395 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12396 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12397 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12398 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12399 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12400 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12401 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12402 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012403 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12404 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012405 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12406 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12407 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12408" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012409endfun
12410
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012411" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012412" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12413"
12414" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12415" is true) and a command, :Rexplore, which call this function.
12416"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012417" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012418"
12419" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012420fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012421 if exists("s:netrwdrag")
12422 return
12423 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012424" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir."> win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012425" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12426" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012427
12428 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012429 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012430" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012431 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012432 unlet w:netrw_rexfile
12433" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012434 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12437" call Decho("treating as not-netrw-buffer: w:netrw_rexfile<".((exists("w:netrw_rexfile"))? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020012438 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012439
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012440 " ---------------------------
12441 " :Rex issued while in a file
12442 " ---------------------------
12443
Bram Moolenaara6878372014-03-22 21:02:50 +010012444 " record current file so :Rex can return to it from netrw
12445 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012446" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012447
12448 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012449" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012450 return
12451 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012453 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012454 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012455 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012456 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012457 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012458 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012459 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012460 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012461 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012462" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12463 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012464" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12465 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012466 if exists("s:rexposn_".bufnr('%'))
12467 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012468 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012469 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012470" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012471 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012472
Bram Moolenaar85850f32019-07-19 22:05:51 +020012473 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12474 if exists("s:explore_match")
12475 exe "2match netrwMarkFile /".s:explore_match."/"
12476 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012477 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012478
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012479" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012480" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012481endfun
12482
12483" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012484" s:SaveBufVars: save selected b: variables to s: variables {{{2
12485" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012486fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012487" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012488
12489 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12490 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12491 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12492 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12493 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12494 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12495
12496" call Dret("s:SaveBufVars")
12497endfun
12498
12499" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012500" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12501fun! s:SavePosn(posndict)
12502" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12503
Bram Moolenaar85850f32019-07-19 22:05:51 +020012504 if !exists("a:posndict[bufnr('%')]")
12505 let a:posndict[bufnr("%")]= []
12506 endif
12507" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12508 call add(a:posndict[bufnr("%")],winsaveview())
12509" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012510
12511" call Dret("s:SavePosn posndict")
12512 return a:posndict
12513endfun
12514
12515" ---------------------------------------------------------------------
12516" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12517fun! s:RestorePosn(posndict)
12518" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012519 if exists("a:posndict")
12520 if has_key(a:posndict,bufnr("%"))
12521" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12522 let posnlen= len(a:posndict[bufnr("%")])
12523 if posnlen > 0
12524 let posnlen= posnlen - 1
12525" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12526 call winrestview(a:posndict[bufnr("%")][posnlen])
12527 call remove(a:posndict[bufnr("%")],posnlen)
12528" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12529 endif
12530 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012531 endif
12532" call Dret("s:RestorePosn")
12533endfun
12534
12535" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012536" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012537fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012538" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012539 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12540 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12541 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12542 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12543 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12544 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12545 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12546 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12547 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12548 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12549 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12550 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12551 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12552 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12553 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12554 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12555 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12556 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12557" call Dret("s:SaveWinVars")
12558endfun
12559
12560" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012561" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012562" To allow separate windows to have their own activities, such as
12563" Explore **/pattern, several variables have been made window-oriented.
12564" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012565" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012566" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012567fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012568" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012569 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12570 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12571 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12572 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12573 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12574 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12575 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12576 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12577 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12578 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12579" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012580endfun
12581
12582" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012583" s:SetRexDir: set directory for :Rexplore {{{2
12584fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012585" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012586 let w:netrw_rexdir = a:dirname
12587 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012588 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012589" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12590" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012591" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012592" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012593" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012594endfun
12595
12596" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012597" s:ShowLink: used to modify thin and tree listings to show links {{{2
12598fun! s:ShowLink()
12599" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012600" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12601" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012602 if exists("b:netrw_curdir")
12603 norm! $?\a
12604 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12605 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012606" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12607" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12608" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12609 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012610 let dirlen = strlen(b:netrw_curdir)
12611 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012613 endif
12614 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012615" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12616" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012617 setl noro ma
12618 call setline(".",modline)
12619 setl ro noma nomod
12620 endif
12621" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12622endfun
12623
12624" ---------------------------------------------------------------------
12625" s:ShowStyle: {{{2
12626fun! s:ShowStyle()
12627 if !exists("w:netrw_liststyle")
12628 let liststyle= g:netrw_liststyle
12629 else
12630 let liststyle= w:netrw_liststyle
12631 endif
12632 if liststyle == s:THINLIST
12633 return s:THINLIST.":thin"
12634 elseif liststyle == s:LONGLIST
12635 return s:LONGLIST.":long"
12636 elseif liststyle == s:WIDELIST
12637 return s:WIDELIST.":wide"
12638 elseif liststyle == s:TREELIST
12639 return s:TREELIST.":tree"
12640 else
12641 return 'n/a'
12642 endif
12643endfun
12644
12645" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12647" Solution from Nicolai Weibull, vim docs (:help strlen()),
12648" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012649fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12651
12652 if v:version >= 703 && exists("*strdisplaywidth")
12653 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012654
Bram Moolenaar8d043172014-01-23 14:24:41 +010012655 elseif type(g:Align_xstrlen) == 1
12656 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12657 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012658
Bram Moolenaar8d043172014-01-23 14:24:41 +010012659 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012660 " number of codepoints (Latin a + combining circumflex is two codepoints)
12661 " (comment from TM, solution from NW)
12662 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012663
Bram Moolenaar8d043172014-01-23 14:24:41 +010012664 elseif g:Align_xstrlen == 2
12665 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012666 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12667 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012668 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012669
Bram Moolenaar8d043172014-01-23 14:24:41 +010012670 elseif g:Align_xstrlen == 3
12671 " virtual length (counting, for instance, tabs as anything between 1 and
12672 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012673 " preceded by lam, one otherwise, etc.)
12674 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675 let modkeep= &l:mod
12676 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012677 call setline(line("."),a:x)
12678 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012679 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012680 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012681 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012682
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 else
12684 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012685 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012686 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012687" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012688 return ret
12689endfun
12690
12691" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012692" s:ShellEscape: shellescape(), or special windows handling {{{2
12693fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012694 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012695 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12696 endif
12697 let f = a:0 > 0 ? a:1 : 0
12698 return shellescape(a:s, f)
12699endfun
12700
12701" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012702" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012703fun! s:TreeListMove(dir)
12704" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012705 let curline = getline('.')
12706 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12707 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12708 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12709 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12710 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12711 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12712" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12713" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12714" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12715" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12716" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12717 " COMBAK : need to handle when on a directory
12718 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012719 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012720 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012721 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012722 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012723" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 elseif a:dir == '[]' && nxtline != ''
12725 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012726" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012727 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12728 if nl != 0
12729 NetrwKeepj norm! k
12730 else
12731 NetrwKeepj norm! G
12732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012733" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012734 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012735 endif
12736
12737" call Dret("s:TreeListMove")
12738endfun
12739
12740" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012741" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12742" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12743" can't be called except via emenu. But due to locale, that menu line may not be called
12744" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12745fun! s:UpdateBuffersMenu()
12746" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012747 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012748 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012749 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012750 catch /^Vim\%((\a\+)\)\=:E/
12751 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012752 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012753 endtry
12754 endif
12755" call Dret("s:UpdateBuffersMenu")
12756endfun
12757
12758" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012759" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012760" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012761fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012762" call Dfunc("s:UseBufWinVars()")
12763 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012764 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12765 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12766 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12767 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12768 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12769 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12770 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12771 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12772 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012773" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012774endfun
12775
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012776" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012777" s:UserMaps: supports user-defined UserMaps {{{2
12778" * calls a user-supplied funcref(islocal,curdir)
12779" * interprets result
12780" See netrw#UserMaps()
12781fun! s:UserMaps(islocal,funcname)
12782" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12783
12784 if !exists("b:netrw_curdir")
12785 let b:netrw_curdir= getcwd()
12786 endif
12787 let Funcref = function(a:funcname)
12788 let result = Funcref(a:islocal)
12789
12790 if type(result) == 1
12791 " if result from user's funcref is a string...
12792" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12793 if result == "refresh"
12794" call Decho("refreshing display",'~'.expand("<slnum>"))
12795 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12796 elseif result != ""
12797" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12798 exe result
12799 endif
12800
12801 elseif type(result) == 3
12802 " if result from user's funcref is a List...
12803" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12804 for action in result
12805 if action == "refresh"
12806" call Decho("refreshing display",'~'.expand("<slnum>"))
12807 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12808 elseif action != ""
12809" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12810 exe action
12811 endif
12812 endfor
12813 endif
12814
12815" call Dret("s:UserMaps")
12816endfun
12817
Bram Moolenaar85850f32019-07-19 22:05:51 +020012818" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012819" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012820" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012821let &cpo= s:keepcpo
12822unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012823
Bram Moolenaar85850f32019-07-19 22:05:51 +020012824" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012825" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012826" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012827" vim:ts=8 fdm=marker