blob: e747ce217d7ad1452732a52f097c5c8faac6ed51 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Travis Sheltone34d0e32024-07-30 21:08:56 +020026" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010027" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000028" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010029" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000030" Permission is hereby granted to use and distribute this code,
31" with or without modifications, provided that this copyright
32" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000033" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000034" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000035" expressed or implied. By using this plugin, you agree that
36" in no event will the copyright holder be liable for any damages
37" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010038"
39" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
40" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
41"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020042"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000043"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000044" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000045" (James 1:22 RSV)
46" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000047" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000048if &cp || exists("g:loaded_netrw")
49 finish
50endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020051
52" Check that vim has patches that netrw requires.
53" Patches needed for v7.4: 1557, and 213.
54" (netrw will benefit from vim's having patch#656, too)
55let s:needspatches=[1557,213]
56if exists("s:needspatches")
57 for ptch in s:needspatches
58 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
59 if !exists("s:needpatch{ptch}")
60 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
61 endif
62 let s:needpatch{ptch}= 1
63 finish
64 endif
65 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020066endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020067
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010068let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000069
Bram Moolenaar1afcace2005-11-25 19:54:28 +000070let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010071setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020072"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010073"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010074"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000075
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000076" ======================
77" Netrw Variables: {{{1
78" ======================
79
Bram Moolenaar071d4272004-06-13 20:20:40 +000080" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020081" netrw#ErrorMsg: {{{2
82" 0=note = s:NOTE
83" 1=warning = s:WARNING
84" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010085" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
86" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
87" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010088" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020089fun! netrw#ErrorMsg(level,msg,errnum)
90" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
91
92 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020093" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020094 return
95 endif
96
97 if a:level == 1
98 let level= "**warning** (netrw) "
99 elseif a:level == 2
100 let level= "**error** (netrw) "
101 else
102 let level= "**note** (netrw) "
103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100104" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200105
Damienb4d11642024-08-15 22:00:45 +0200106 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200107 " use popup window
108 if type(a:msg) == 3
109 let msg = [level]+a:msg
110 else
111 let msg= level.a:msg
112 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200113 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200114 let s:popuperr_text= ""
115 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200116 " (default) netrw creates a one-line window to show error/warning
117 " messages (reliably displayed)
118
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100119 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100121" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122
123 " getting messages out reliably is just plain difficult!
124 " This attempt splits the current window, creating a one line window.
125 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100126" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100128" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100130 if type(a:msg) == 3
131 for msg in a:msg
132 NetrwKeepj call setline(line("$")+1,level.msg)
133 endfor
134 else
135 NetrwKeepj call setline(line("$")+1,level.a:msg)
136 endif
137 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 bo 1split
141 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200142 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100144 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100145" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100147 if type(a:msg) == 3
148 for msg in a:msg
149 NetrwKeepj call setline(line("$")+1,level.msg)
150 endfor
151 else
152 NetrwKeepj call setline(line("$"),level.a:msg)
153 endif
154 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100156" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 if &fo !~ '[ta]'
158 syn clear
159 syn match netrwMesgNote "^\*\*note\*\*"
160 syn match netrwMesgWarning "^\*\*warning\*\*"
161 syn match netrwMesgError "^\*\*error\*\*"
162 hi link netrwMesgWarning WarningMsg
163 hi link netrwMesgError Error
164 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100165" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200166 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200167
168 else
169 " (optional) netrw will show messages using echomsg. Even if the
170 " message doesn't appear, at least it'll be recallable via :messages
171" redraw!
172 if a:level == s:WARNING
173 echohl WarningMsg
174 elseif a:level == s:ERROR
175 echohl Error
176 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100177
178 if type(a:msg) == 3
179 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100180 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100181 endfor
182 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100183 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100184 endif
185
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100186" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200187 echohl None
188 endif
189
190" call Dret("netrw#ErrorMsg")
191endfun
192
193" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100194" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100195" Loosely, varname = value.
196fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100197" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100198 if !exists(a:varname)
199 if type(a:value) == 0
200 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200201 elseif type(a:value) == 1 && a:value =~ '^[{[]'
202 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100203 elseif type(a:value) == 1
204 exe "let ".a:varname."="."'".a:value."'"
205 else
206 exe "let ".a:varname."=".a:value
207 endif
208 endif
209endfun
210
211" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000212" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200213call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000214if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100215 call s:NetrwInit("s:THINLIST",0)
216 call s:NetrwInit("s:LONGLIST",1)
217 call s:NetrwInit("s:WIDELIST",2)
218 call s:NetrwInit("s:TREELIST",3)
219 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000220endif
221
Damien7c754112024-08-15 21:58:57 +0200222let s:NOTE = 0
223let s:WARNING = 1
224let s:ERROR = 2
225call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
226
Bram Moolenaar9964e462007-05-05 17:54:07 +0000227" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200228" Default option values: {{{2
229let g:netrw_localcopycmdopt = ""
230let g:netrw_localcopydircmdopt = ""
231let g:netrw_localmkdiropt = ""
232let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200233
234" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000235" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200236if exists("*popup_atcursor")
237\ && has("syntax")
238\ && exists("g:syntax_on")
239\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200240 call s:NetrwInit("g:netrw_use_errorwindow",2)
241else
242 call s:NetrwInit("g:netrw_use_errorwindow",1)
243endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200244
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000245if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100246 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000247 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100248 elseif executable("curl")
249 let g:netrw_dav_cmd = "curl"
250 else
251 let g:netrw_dav_cmd = ""
252 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000254if !exists("g:netrw_fetch_cmd")
255 if executable("fetch")
256 let g:netrw_fetch_cmd = "fetch -o"
257 else
258 let g:netrw_fetch_cmd = ""
259 endif
260endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100261if !exists("g:netrw_file_cmd")
262 if executable("elinks")
263 call s:NetrwInit("g:netrw_file_cmd","elinks")
264 elseif executable("links")
265 call s:NetrwInit("g:netrw_file_cmd","links")
266 endif
267endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000268if !exists("g:netrw_ftp_cmd")
269 let g:netrw_ftp_cmd = "ftp"
270endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200271let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200272if !exists("g:netrw_ftp_options")
273 let g:netrw_ftp_options= "-i -n"
274endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000275if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100276 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100277 let g:netrw_http_cmd = "wget"
278 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100279 elseif executable("curl")
280 let g:netrw_http_cmd = "curl"
281 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200282 elseif executable("elinks")
283 let g:netrw_http_cmd = "elinks"
284 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000285 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100286 let g:netrw_http_cmd = "fetch"
287 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200288 elseif executable("links")
289 let g:netrw_http_cmd = "links"
290 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000291 else
292 let g:netrw_http_cmd = ""
293 endif
294endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100295call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100296call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100297call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
298call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200299call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200300if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200301 if executable("scp")
302 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
303 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200304 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200305 else
306 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
307 endif
308endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100309call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
310call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000311
Nir Lichtman1e34b952024-05-08 19:19:34 +0200312if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000313 \ && exists("g:netrw_use_nt_rcp")
314 \ && g:netrw_use_nt_rcp
315 \ && executable( $SystemRoot .'/system32/rcp.exe')
316 let s:netrw_has_nt_rcp = 1
317 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000318else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000319 let s:netrw_has_nt_rcp = 0
320 let s:netrw_rcpmode = ''
321endif
322
323" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000324" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000325" Cygwin Detection ------- {{{3
326if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200327 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
328 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000329 else
330 let g:netrw_cygwin= 0
331 endif
332endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000333" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100334call s:NetrwInit("g:netrw_alto" , &sb)
335call s:NetrwInit("g:netrw_altv" , &spr)
336call s:NetrwInit("g:netrw_banner" , 1)
337call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200338call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100339call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200340call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100341call s:NetrwInit("g:netrw_compress" , "gzip")
342call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200343if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
344 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
345 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000346endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200347call s:NetrwInit("g:netrw_cursor" , 2)
348let s:netrw_usercul = &cursorline
349let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200350"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100351call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000352" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200353call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200354call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200355call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100356call s:NetrwInit("g:netrw_dirhistmax" , 10)
357call s:NetrwInit("g:netrw_fastbrowse" , 1)
358call 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 +0000359if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000360 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
361 let g:netrw_ftp_list_cmd = "ls -lF"
362 let g:netrw_ftp_timelist_cmd = "ls -tlF"
363 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000364 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000365 let g:netrw_ftp_list_cmd = "dir"
366 let g:netrw_ftp_timelist_cmd = "dir"
367 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000368 endif
369endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100370call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000371" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100372call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373if !exists("g:netrw_ignorenetrc")
374 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
375 let g:netrw_ignorenetrc= 1
376 else
377 let g:netrw_ignorenetrc= 0
378 endif
379endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100380call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000381if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000382 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100383 if exists("g:netrw_list_cmd_options")
384 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
385 else
386 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
387 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000388 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200389 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100390 if exists("g:netrw_list_cmd_options")
391 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
392 else
393 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
394 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000395 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100396" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000397 let g:netrw_list_cmd= ""
398 endif
399endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100400call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000401" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200402if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200403 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200404 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
405endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100406if !exists("g:netrw_localcmdshell")
407 let g:netrw_localcmdshell= ""
408endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000409if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200410 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000411 if g:netrw_cygwin
412 let g:netrw_localcopycmd= "cp"
413 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000414 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200415 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000416 endif
417 elseif has("unix") || has("macunix")
418 let g:netrw_localcopycmd= "cp"
419 else
420 let g:netrw_localcopycmd= ""
421 endif
422endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200424 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100425 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200426 let g:netrw_localcopydircmd = "cp"
427 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000429 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200430 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200432 elseif has("unix")
433 let g:netrw_localcopydircmd = "cp"
434 let g:netrw_localcopydircmdopt= " -R"
435 elseif has("macunix")
436 let g:netrw_localcopydircmd = "cp"
437 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100438 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200439 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100440 endif
441endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200442if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100443 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200444 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
445endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200446if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200447 if g:netrw_cygwin
448 call s:NetrwInit("g:netrw_localmkdir","mkdir")
449 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000450 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200451 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200452 endif
453else
454 call s:NetrwInit("g:netrw_localmkdir","mkdir")
455endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200456call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200457if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200458 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200459 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
460endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000461if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200462 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000463 if g:netrw_cygwin
464 let g:netrw_localmovecmd= "mv"
465 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000466 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200467 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000468 endif
469 elseif has("unix") || has("macunix")
470 let g:netrw_localmovecmd= "mv"
471 else
472 let g:netrw_localmovecmd= ""
473 endif
474endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100475" following serves as an example for how to insert a version&patch specific test
476"if v:version < 704 || (v:version == 704 && !has("patch1107"))
477"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100478call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
479" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000480if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000481 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000482endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000483if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000484 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
485endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000486" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100487call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
488call s:NetrwInit("g:netrw_maxfilenamelen", 32)
489call s:NetrwInit("g:netrw_menu" , 1)
490call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200491call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_retmap" , 0)
493if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
494 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200495elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100496 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
497else
498 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000499endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100500call s:NetrwInit("g:netrw_preview" , 0)
501call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100502call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100503call s:NetrwInit("g:netrw_sshport" , "-p")
504call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
505call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
506call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100507call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
508" Default values - q-s ---------- {{{3
509call s:NetrwInit("g:netrw_quickhelp",0)
510let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100511 \ "(create new) %:file d:directory",
512 \ "(windows split&open) o:horz v:vert p:preview",
513 \ "i:style qf:file info O:obtain r:reverse",
514 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
515 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
516 \ "(history) qb:list u:go up U:go down",
517 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
519call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100520if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
521 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
522else
523 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
524endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
526call s:NetrwInit("g:netrw_sort_options" , "")
527call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000528if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200530 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531 else
532 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000533 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000534endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535call s:NetrwInit("g:netrw_special_syntax" , 0)
536call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200537call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100538call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100539call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000540" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200542if !exists("g:netrw_xstrlen")
543 if exists("g:Align_xstrlen")
544 let g:netrw_xstrlen= g:Align_xstrlen
545 elseif exists("g:drawit_xstrlen")
546 let g:netrw_xstrlen= g:drawit_xstrlen
547 elseif &enc == "latin1" || !has("multi_byte")
548 let g:netrw_xstrlen= 0
549 else
550 let g:netrw_xstrlen= 1
551 endif
552endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100553call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200554call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100555call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200556if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000557" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000558" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100559call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200560if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200561 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200562else
Bram Moolenaarff034192013-04-24 18:51:19 +0200563 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200564endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200565call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100566call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
567call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100568if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100569 let s:treedepthstring= "│ "
570else
571 let s:treedepthstring= "| "
572endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200573call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000574
575" BufEnter event ignored by decho when following variable is true
576" Has a side effect that doau BufReadPost doesn't work, so
577" files read by network transfer aren't appropriately highlighted.
578"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579
Bram Moolenaaradc21822011-04-01 18:03:16 +0200580" ======================
581" Netrw Initialization: {{{1
582" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200583if 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 +0100584" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100585 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200586" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100587 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100588 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
589 au VimEnter * let s:initbeval= &beval
590"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100591" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
592" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
593" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
594" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
595" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
596" 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 +0200597endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200598au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200599
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200600if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100601 com! -nargs=* NetrwKeepj keepj <args>
602else
603 let g:netrw_keepj= ""
604 com! -nargs=* NetrwKeepj <args>
605endif
606
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000607" ==============================
608" Netrw Utility Functions: {{{1
609" ==============================
610
Bram Moolenaaradc21822011-04-01 18:03:16 +0200611" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100612" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100613if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100614" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100615 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100616 if &ft != "netrw"
617 return ""
618 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200619 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
620 " popup error window is still showing
621 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
622 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
623 " text under mouse hasn't changed; only close window when it changes
624 call popup_close(s:popuperr_id)
625 unlet s:popuperr_text
626 else
627 let s:popuperr_text= v:beval_text
628 endif
629 let mesg= ""
630 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 +0100631 let mesg= ""
632 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
633 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
634 elseif getline(v:beval_lnum) =~ '^"\s*/'
635 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
636 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100637 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100638 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
639 let mesg = "S: edit sorting sequence"
640 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
641 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
642 elseif v:beval_text == "Quick" || v:beval_text == "Help"
643 let mesg = "Help: press <F1>"
644 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
645 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
646 else
647 let mesg= ""
648 endif
649 return mesg
650 endfun
651"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100652" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
653" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
654" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
655" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
656" 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 +0200657endif
658
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200660" netrw#Explore: launch the local browser in the directory of the current file {{{2
661" indx: == -1: Nexplore
662" == -2: Pexplore
663" == +: this is overloaded:
664" * If Nexplore/Pexplore is in use, then this refers to the
665" indx'th item in the w:netrw_explore_list[] of items which
666" matched the */pattern **/pattern *//pattern **//pattern
667" * If Hexplore or Vexplore, then this will override
668" g:netrw_winsize to specify the qty of rows or columns the
669" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100670" 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 +0200671" dosplit==1: the window will be split before running the local browser
672" style == 0: Explore style == 1: Explore!
673" == 2: Hexplore style == 3: Hexplore!
674" == 4: Vexplore style == 5: Vexplore!
675" == 6: Texplore
676fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100677" 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 +0100678" 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 +0200679 if !exists("b:netrw_curdir")
680 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100681" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200682 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100683
684 " record current file for Rexplore's benefit
685 if &ft != "netrw"
686 let w:netrw_rexfile= expand("%:p")
687 endif
688
689 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200690 let curdir = simplify(b:netrw_curdir)
691 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200692 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200693 let curdir= substitute(curdir,'\','/','g')
694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100695" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100696
697 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
698 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
699 " try Explore again.
700 if a:0 > 0
701" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100702 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
703 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
704 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
705 \ '~'.expand("<slnum>"))
706 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200707 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
708 if a1 != a:1
709 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
710 return
711 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100712 endif
713 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200714
715 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200716 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100717" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100718 sil! let keepregstar = @*
719 sil! let keepregplus = @+
720 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200721 sil! let keepregslash= @/
722
Bram Moolenaar8d043172014-01-23 14:24:41 +0100723 " if dosplit
724 " -or- file has been modified AND file not hidden when abandoned
725 " -or- Texplore used
726 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 call s:SaveWinVars()
728 let winsz= g:netrw_winsize
729 if a:indx > 0
730 let winsz= a:indx
731 endif
732
733 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200735 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200736 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200737
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200738 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200739 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200740 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200741 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200742
743 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200745 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200746 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200747
748 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200749 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200750 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200751 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200754 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200755 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200756 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200757
758 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200759 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200760 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200761 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200762
763 elseif a:style == 6 " Texplore
764 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 exe "keepalt tabnew ".fnameescape(curdir)
766 call s:RestoreBufVars()
767 endif
768 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100770 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200771
772 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100773" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
781 if dirname !~ '/$'
782 let dirname= dirname."/"
783 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200789 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= a:1
796 endif
797 else
798 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 call s:NetrwClearExplore()
801" call Dret("netrw#Explore : cleared list")
802 return
803 endif
804
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 if dirname =~ '\.\./\=$'
807 let dirname= simplify(fnamemodify(dirname,':p:h'))
808 elseif dirname =~ '\.\.' || dirname == '.'
809 let dirname= simplify(fnamemodify(dirname,':p'))
810 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100811" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200812
813 if dirname =~ '^\*//'
814 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100815" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
817 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
820
821 elseif dirname =~ '^\*\*//'
822 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let pattern= substitute(dirname,'^\*\*//','','')
825 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827
828 elseif dirname =~ '/\*\*/'
829 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200832 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 let b:netrw_curdir = prefixdir
834 else
835 let b:netrw_curdir= getcwd().'/'.prefixdir
836 endif
837 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
838 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100839" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
840" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841
842 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200843 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200844 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200846
847 elseif dirname=~ '^\*\*/'
848 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
849 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200851
852 else
853 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 endif
856
857 if starpat == 0 && a:indx >= 0
858 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" 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 +0200860 if dirname == ""
861 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200864 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200865 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200866 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200867 if dirname == ""
868 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200869 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100871 " depending on whether backslashes have been converted to forward slashes by earlier code).
872 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 let dirname= b:netrw_curdir."/".dirname
874 endif
875 elseif dirname !~ '^/'
876 let dirname= b:netrw_curdir."/".dirname
877 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100878" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200879 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100880" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
881" 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 +0200882 endif
883 if exists("w:netrw_bannercnt")
884 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
885 " If one wants to return the same place in the netrw window, use :Rex instead.
886 exe w:netrw_bannercnt
887 endif
888
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 " ---------------------------------------------------------------------
891 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
892" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100893" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200894" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100895" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200896" endif
897 " ---------------------------------------------------------------------
898
899 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
900 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
901 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
902 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
903 elseif a:indx <= 0
904 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100905" 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 +0200906 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100907" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200908 let s:didstarstar= 1
909 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
910 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
911 endif
912
913 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100914" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200915 if !exists("w:netrw_explore_indx")
916 let w:netrw_explore_indx= 0
917 endif
918
919 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100920" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200921
922 if indx == -1
923 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100924" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200925 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100926 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 +0200927 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100928" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100929 if @* != keepregstar | sil! let @* = keepregstar | endif
930 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100931 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200932 sil! let @/ = keepregslash
933" call Dret("netrw#Explore")
934 return
935 endif
936 let indx= w:netrw_explore_indx
937 if indx < 0 | let indx= 0 | endif
938 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
939 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100940" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
942 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100943" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200944 endwhile
945 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100946" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200947
948 elseif indx == -2
949 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100950" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200951 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100952 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 +0200953 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100954" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100955 if @* != keepregstar | sil! let @* = keepregstar | endif
956 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100957 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200958 sil! let @/ = keepregslash
959" call Dret("netrw#Explore")
960 return
961 endif
962 let indx= w:netrw_explore_indx
963 if indx < 0 | let indx= 0 | endif
964 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
965 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100966" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200967 while indx >= 0 && curfile == w:netrw_explore_list[indx]
968 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100969" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 endwhile
971 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200973
974 else
975 " Explore -- initialize
976 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100978 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 let w:netrw_explore_indx= 0
980 if !exists("b:netrw_curdir")
981 let b:netrw_curdir= getcwd()
982 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200984
985 " switch on starpat to build the w:netrw_explore_list of files
986 if starpat == 1
987 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100988" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
989" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100991 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 catch /^Vim\%((\a\+)\)\=:E480/
993 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
994" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
995 return
996 endtry
997 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
998 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
999
1000 elseif starpat == 2
1001 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001002" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1003" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001004 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001005 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 catch /^Vim\%((\a\+)\)\=:E480/
1007 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1008 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001009 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001010" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001011 if @* != keepregstar | sil! let @* = keepregstar | endif
1012 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001013 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001014 sil! let @/ = keepregslash
1015" call Dret("netrw#Explore : no files matched pattern")
1016 return
1017 endtry
1018 let s:netrw_curdir = b:netrw_curdir
1019 let w:netrw_explore_list = getqflist()
1020 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1021 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1022
1023 elseif starpat == 3
1024 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001025" 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 +02001026 let filepat= substitute(dirname,'^\*/','','')
1027 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001028" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1029" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001030 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1031 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1032
1033 elseif starpat == 4
1034 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001035" 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 +02001036 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1037 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1038 endif " switch on starpat to build w:netrw_explore_list
1039
1040 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001041" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1042" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001043
1044 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001045 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001046 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001047" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001048 if @* != keepregstar | sil! let @* = keepregstar | endif
1049 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001050 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001051 sil! let @/ = keepregslash
1052" call Dret("netrw#Explore : no files matched")
1053 return
1054 endif
1055 endif " if indx ... endif
1056
1057 " NetrwStatusLine support - for exploring support
1058 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001059" 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 +02001060
1061 " wrap the indx around, but issue a note
1062 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001063" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001064 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1065 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001066 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001067 endif
1068
1069 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 call netrw#LocalBrowseCheck(newdir)
1076 if !exists("w:netrw_liststyle")
1077 let w:netrw_liststyle= g:netrw_liststyle
1078 endif
1079 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001080 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001082 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 endif
1084 let w:netrw_explore_mtchcnt = indx + 1
1085 let w:netrw_explore_bufnr = bufnr("%")
1086 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001087 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001088" 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 +02001089
1090 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001091" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 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 +02001094 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001095 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001096" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001097 if @* != keepregstar | sil! let @* = keepregstar | endif
1098 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001099 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001100 sil! let @/ = keepregslash
1101" call Dret("netrw#Explore : missing +path_extra")
1102 return
1103 endif
1104
1105 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001106" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001107 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1108 sil! unlet w:netrw_treedict
1109 sil! unlet w:netrw_treetop
1110 endif
1111 let newdir= dirname
1112 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001113 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001115 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 endif
1117 endif
1118
1119 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001120" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1121" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001123" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001125 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001126" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 let s:explore_prvdir = b:netrw_curdir
1128 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001129 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if b:netrw_curdir !~ '/$'
1131 let dirlen= dirlen + 1
1132 endif
1133 let prvfname= ""
1134 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001135" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 if fname =~ '^'.b:netrw_curdir
1137 if s:explore_match == ""
1138 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1139 else
1140 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1141 endif
1142 elseif fname !~ '^/' && fname != prvfname
1143 if s:explore_match == ""
1144 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1145 else
1146 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1147 endif
1148 endif
1149 let prvfname= fname
1150 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001151" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001152 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1153 exe "2match netrwMarkFile /".s:explore_match."/"
1154 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001155 endif
1156 echo "<s-up>==Pexplore <s-down>==Nexplore"
1157 else
1158 2match none
1159 if exists("s:explore_match") | unlet s:explore_match | endif
1160 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001161" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001162 endif
1163
Bram Moolenaara6878372014-03-22 21:02:50 +01001164 " since Explore may be used to initialize netrw's browser,
1165 " there's no danger of a late FocusGained event on initialization.
1166 " Consequently, set s:netrw_events to 2.
1167 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001168 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001169" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001170 if @* != keepregstar | sil! let @* = keepregstar | endif
1171 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001172 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001173 sil! let @/ = keepregslash
1174" call Dret("netrw#Explore : @/<".@/.">")
1175endfun
1176
1177" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001178" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001179" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1180" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1181" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1182" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1183" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001184fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001185" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186 let curwin= winnr()
1187
Bram Moolenaara6878372014-03-22 21:02:50 +01001188 if a:0 > 0 && a:1 != ""
1189 " if a netrw window is already on the left-side of the tab
1190 " and a directory has been specified, explore with that
1191 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001192" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001194" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001195 exe "1wincmd w"
1196 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001197" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 exe "Explore ".fnameescape(a1)
1199 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001200 let s:lexplore_win= curwin
1201 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001203" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 unlet t:netrw_lexposn
1205 endif
1206" call Dret("netrw#Lexplore")
1207 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001208 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 exe curwin."wincmd w"
1210 else
1211 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001212" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001213 endif
1214
Bram Moolenaar8d043172014-01-23 14:24:41 +01001215 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001216 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001217 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001218" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 else
1220 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224
1225 if lexwinnr > 0
1226 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 exe lexwinnr."wincmd w"
1229 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001230 let t:netrw_lexposn = winsaveview()
1231" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001232" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 close
1234 if lexwinnr < curwin
1235 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001236 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001237 if lexwinnr != curwin
1238 exe curwin."wincmd w"
1239 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001240 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001241" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001242
1243 else
1244 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001245" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246 exe "1wincmd w"
1247 let keep_altv = g:netrw_altv
1248 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001249 if a:count != 0
1250 let netrw_winsize = g:netrw_winsize
1251 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001252 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001253 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001254" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 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 +02001256" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001258" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001259 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001261 elseif curfile =~ '^\a\{3,}://'
1262" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001263 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001266 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 endif
1268 if a:count != 0
1269 let g:netrw_winsize = netrw_winsize
1270 endif
1271 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001272 let g:netrw_altv = keep_altv
1273 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001274 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1275 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001276 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001277 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001278" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1279" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001280 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001281" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001282" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1283 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001284 unlet t:netrw_lexposn
1285 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001286 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001287
1288 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001289 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290 if a:rightside
1291 let g:netrw_chgwin= 1
1292 else
1293 let g:netrw_chgwin= 2
1294 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001295" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001296 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001297
Bram Moolenaar8d043172014-01-23 14:24:41 +01001298" call Dret("netrw#Lexplore")
1299endfun
1300
1301" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001302" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001303" supports :NetrwClean -- remove netrw from first directory on runtimepath
1304" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001305fun! netrw#Clean(sys)
1306" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001307
1308 if a:sys
1309 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1310 else
1311 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1312 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001313" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001314 let diddel= 0
1315 let diddir= ""
1316
1317 if choice == 1
1318 for dir in split(&rtp,',')
1319 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001320" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001321 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1322 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1323 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1324 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1325 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1326 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 +00001327 let diddir= dir
1328 let diddel= diddel + 1
1329 if !a:sys|break|endif
1330 endif
1331 endfor
1332 endif
1333
1334 echohl WarningMsg
1335 if diddel == 0
1336 echomsg "netrw is either not installed or not removable"
1337 elseif diddel == 1
1338 echomsg "removed one copy of netrw from <".diddir.">"
1339 else
1340 echomsg "removed ".diddel." copies of netrw"
1341 endif
1342 echohl None
1343
Bram Moolenaara6878372014-03-22 21:02:50 +01001344" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001345endfun
1346
Bram Moolenaar5c736222010-01-06 20:54:52 +01001347" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001348" netrw#MakeTgt: make a target out of the directory name provided {{{2
1349fun! netrw#MakeTgt(dname)
1350" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1351 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001352 let svpos = winsaveview()
1353" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001354 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1355" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001356 if s:netrwmftgt_islocal
1357 let netrwmftgt= simplify(a:dname)
1358 else
1359 let netrwmftgt= a:dname
1360 endif
1361 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1362 " re-selected target, so just clear it
1363 unlet s:netrwmftgt s:netrwmftgt_islocal
1364 else
1365 let s:netrwmftgt= netrwmftgt
1366 endif
1367 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001368 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001369 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001370" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1371 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001372" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001373endfun
1374
Bram Moolenaara6878372014-03-22 21:02:50 +01001375" ---------------------------------------------------------------------
1376" netrw#Obtain: {{{2
1377" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001378" islocal=0 obtain from remote source
1379" =1 obtain from local source
1380" fname : a filename or a list of filenames
1381" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001382fun! netrw#Obtain(islocal,fname,...)
1383" 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 +02001384 " NetrwStatusLine support - for obtaining support
1385
1386 if type(a:fname) == 1
1387 let fnamelist= [ a:fname ]
1388 elseif type(a:fname) == 3
1389 let fnamelist= a:fname
1390 else
1391 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 +01001392" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001393 return
1394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001395" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 if a:0 > 0
1397 let tgtdir= a:1
1398 else
1399 let tgtdir= getcwd()
1400 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001401" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001402
1403 if exists("b:netrw_islocal") && b:netrw_islocal
1404 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1407 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001408 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001413 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 if v:shell_error != 0
1415 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 +01001416" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 return
1418 endif
1419 endfor
1420 else
1421 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001422" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1423 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1424" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001425 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001426 if v:shell_error != 0
1427 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 +01001428" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001429 return
1430 endif
1431 endif
1432 elseif !exists("b:netrw_curdir")
1433 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1434 else
1435 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1436 endif
1437
1438 else
1439 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001440" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001441 if type(a:fname) == 1
1442 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1443 endif
1444 call s:NetrwMethod(b:netrw_curdir)
1445
1446 if b:netrw_method == 4
1447 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 if exists("g:netrw_port") && g:netrw_port != ""
1450 let useport= " ".g:netrw_scpport." ".g:netrw_port
1451 else
1452 let useport= ""
1453 endif
1454 if b:netrw_fname =~ '/'
1455 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1456 else
1457 let path= ""
1458 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001459 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001460 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 +02001461
1462 elseif b:netrw_method == 2
1463 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001464" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001465 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001466 let tmpbufnr= bufnr("%")
1467 setl ff=unix
1468 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001469 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 endif
1472
1473 if exists("b:netrw_fname") && b:netrw_fname != ""
1474 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 endif
1477
1478 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001480" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 endif
1482 for fname in fnamelist
1483 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endfor
1486 if exists("g:netrw_port") && g:netrw_port != ""
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)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 endif
1491 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1492 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1493 let debugkeep= &debug
1494 setl debug=msg
1495 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1496 let &debug= debugkeep
1497 endif
1498
1499 elseif b:netrw_method == 3
1500 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001501" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001502 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001503 let tmpbufnr= bufnr("%")
1504 setl ff=unix
1505
1506 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001507 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001508" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001509 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001511" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 endif
1513
1514 if exists("g:netrw_uid") && g:netrw_uid != ""
1515 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001521" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 endif
1526 endif
1527
1528 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001529 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001530" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endif
1532
1533 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537
1538 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001539 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001540" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001541 endif
1542
1543 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 endif
1547 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001548 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001550" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001551
1552 " perform ftp:
1553 " -i : turns off interactive prompting from ftp
1554 " -n unix : DON'T use <.netrc>, even though it exists
1555 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001556 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1557 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001558 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001559 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1560 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001561" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001563 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001564 endif
1565 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001566
1567 elseif b:netrw_method == 9
1568 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001569" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001570 if a:fname =~ '/'
1571 let localfile= substitute(a:fname,'^.*/','','')
1572 else
1573 let localfile= a:fname
1574 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001575 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 +02001576
Bram Moolenaarff034192013-04-24 18:51:19 +02001577 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001578 " probably a badly formed url; protocol not recognized
1579" call Dret("netrw#Obtain : unsupported method")
1580 return
1581
1582 else
1583 " protocol recognized but not supported for Obtain (yet?)
1584 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001585 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001586 endif
1587" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001588 return
1589 endif
1590
1591 " restore status line
1592 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001593 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001594 endif
1595
1596 endif
1597
1598 " cleanup
1599 if exists("tmpbufnr")
1600 if bufnr("%") != tmpbufnr
1601 exe tmpbufnr."bw!"
1602 else
1603 q!
1604 endif
1605 endif
1606
Bram Moolenaara6878372014-03-22 21:02:50 +01001607" call Dret("netrw#Obtain")
1608endfun
1609
1610" ---------------------------------------------------------------------
1611" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1612fun! netrw#Nread(mode,fname)
1613" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001614 let svpos= winsaveview()
1615" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001616 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001617" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1618 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001619
1620 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1621 if exists("w:netrw_bannercnt")
1622 " start with cursor just after the banner
1623 exe w:netrw_bannercnt
1624 endif
1625 endif
1626" call Dret("netrw#Nread")
1627endfun
1628
1629" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001630" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1631" Options get restored by s:NetrwOptionsRestore()
1632"
1633" Option handling:
1634" * save user's options (s:NetrwOptionsSave)
1635" * set netrw-safe options (s:NetrwOptionsSafe)
1636" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1637" * restore user's options (s:netrwOPtionsRestore)
1638" - restore a user option when != safe option (s:NetrwRestoreSetting)
1639" vt: (variable type) normally its either "w:" or "s:"
1640fun! s:NetrwOptionsSave(vt)
1641" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1642" 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 +02001643" 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>"))
1644" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001645
1646 if !exists("{a:vt}netrw_optionsave")
1647 let {a:vt}netrw_optionsave= 1
1648 else
1649" call Dret("s:NetrwOptionsSave : options already saved")
1650 return
1651 endif
1652" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1653
1654 " Save current settings and current directory
1655" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1656 let s:yykeep = @@
1657 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1658 let {a:vt}netrw_aikeep = &l:ai
1659 let {a:vt}netrw_awkeep = &l:aw
1660 let {a:vt}netrw_bhkeep = &l:bh
1661 let {a:vt}netrw_blkeep = &l:bl
1662 let {a:vt}netrw_btkeep = &l:bt
1663 let {a:vt}netrw_bombkeep = &l:bomb
1664 let {a:vt}netrw_cedit = &cedit
1665 let {a:vt}netrw_cikeep = &l:ci
1666 let {a:vt}netrw_cinkeep = &l:cin
1667 let {a:vt}netrw_cinokeep = &l:cino
1668 let {a:vt}netrw_comkeep = &l:com
1669 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001670 let {a:vt}netrw_cuckeep = &l:cuc
1671 let {a:vt}netrw_culkeep = &l:cul
1672" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001673 let {a:vt}netrw_diffkeep = &l:diff
1674 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001675 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1676 let {a:vt}netrw_ffkeep = &l:ff
1677 endif
1678 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1679 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001680 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001681 let {a:vt}netrw_hidkeep = &l:hidden
1682 let {a:vt}netrw_imkeep = &l:im
1683 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001684 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001685 let {a:vt}netrw_lskeep = &l:ls
1686 let {a:vt}netrw_makeep = &l:ma
1687 let {a:vt}netrw_magickeep = &l:magic
1688 let {a:vt}netrw_modkeep = &l:mod
1689 let {a:vt}netrw_nukeep = &l:nu
1690 let {a:vt}netrw_rnukeep = &l:rnu
1691 let {a:vt}netrw_repkeep = &l:report
1692 let {a:vt}netrw_rokeep = &l:ro
1693 let {a:vt}netrw_selkeep = &l:sel
1694 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001695 if !g:netrw_use_noswf
1696 let {a:vt}netrw_swfkeep = &l:swf
1697 endif
1698 let {a:vt}netrw_tskeep = &l:ts
1699 let {a:vt}netrw_twkeep = &l:tw " textwidth
1700 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1701 let {a:vt}netrw_wrapkeep = &l:wrap
1702 let {a:vt}netrw_writekeep = &l:write
1703
1704 " save a few selected netrw-related variables
1705" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1706 if g:netrw_keepdir
1707 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001708" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001709 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001710 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001711 sil! let {a:vt}netrw_starkeep = @*
1712 sil! let {a:vt}netrw_pluskeep = @+
1713 endif
1714 sil! let {a:vt}netrw_slashkeep= @/
1715
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001716" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001717" 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>"))
1718" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1719endfun
1720
1721" ---------------------------------------------------------------------
1722" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1723" Use s:NetrwSaveOptions() to save user settings
1724" Use s:NetrwOptionsRestore() to restore user settings
1725fun! s:NetrwOptionsSafe(islocal)
1726" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1727" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1728" 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>"))
1729 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1730 call s:NetrwSetSafeSetting("&l:ai",0)
1731 call s:NetrwSetSafeSetting("&l:aw",0)
1732 call s:NetrwSetSafeSetting("&l:bl",0)
1733 call s:NetrwSetSafeSetting("&l:bomb",0)
1734 if a:islocal
1735 call s:NetrwSetSafeSetting("&l:bt","nofile")
1736 else
1737 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1738 endif
1739 call s:NetrwSetSafeSetting("&l:ci",0)
1740 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001741 if g:netrw_fastbrowse > a:islocal
1742 call s:NetrwSetSafeSetting("&l:bh","hide")
1743 else
1744 call s:NetrwSetSafeSetting("&l:bh","delete")
1745 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001746 call s:NetrwSetSafeSetting("&l:cino","")
1747 call s:NetrwSetSafeSetting("&l:com","")
1748 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1749 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1750 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001751 if &go =~ 'a' | set go-=a | endif
1752 if &go =~ 'A' | set go-=A | endif
1753 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001754 call s:NetrwSetSafeSetting("&l:hid",0)
1755 call s:NetrwSetSafeSetting("&l:im",0)
1756 setl isk+=@ isk+=* isk+=/
1757 call s:NetrwSetSafeSetting("&l:magic",1)
1758 if g:netrw_use_noswf
1759 call s:NetrwSetSafeSetting("swf",0)
1760 endif
1761 call s:NetrwSetSafeSetting("&l:report",10000)
1762 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1763 call s:NetrwSetSafeSetting("&l:spell",0)
1764 call s:NetrwSetSafeSetting("&l:tw",0)
1765 call s:NetrwSetSafeSetting("&l:wig","")
1766 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001767
1768 " set up cuc and cul based on g:netrw_cursor and listing style
1769 " COMBAK -- cuc cul related
1770 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001771
1772 " allow the user to override safe options
1773" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1774 if &ft == "netrw"
1775" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1776 keepalt NetrwKeepj doau FileType netrw
1777 endif
1778
1779" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1780" 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>"))
1781" call Dret("s:NetrwOptionsSafe")
1782endfun
1783
1784" ---------------------------------------------------------------------
1785" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1786fun! s:NetrwOptionsRestore(vt)
1787" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001788" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001789" 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 +01001790 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001791" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001792
1793 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1794 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001795" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001796 filetype detect
1797" 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>"))
1798 else
1799 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001800 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001801" 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 +02001802" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001803 return
1804 endif
1805 unlet {a:vt}netrw_optionsave
1806
1807 if exists("+acd")
1808 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001809" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001810 let curdir = getcwd()
1811 let &l:acd = {a:vt}netrw_acdkeep
1812 unlet {a:vt}netrw_acdkeep
1813 if &l:acd
1814 call s:NetrwLcd(curdir)
1815 endif
1816 endif
1817 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001818" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001819 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1820 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1821 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1822 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1823 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001824" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001825 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1826 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1827 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1828 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1829 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001830" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001831 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1832 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1833 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1834 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1835 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001836 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001837" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1838 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1839 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001840 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1842" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1843 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1844 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1845" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1847" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1848 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1849 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001850 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001851 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1852 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1853" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1855 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1856 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1857 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1858" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001860 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1861 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1862 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001864" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001865 call s:NetrwRestoreSetting("s:yykeep","@@")
1866 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1867 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1868 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1869 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1870
Bram Moolenaara6878372014-03-22 21:02:50 +01001871 if exists("{a:vt}netrw_swfkeep")
1872 if &directory == ""
1873 " user hasn't specified a swapfile directory;
1874 " netrw will temporarily set the swapfile directory
1875 " to the current directory as returned by getcwd().
1876 let &l:directory= getcwd()
1877 sil! let &l:swf = {a:vt}netrw_swfkeep
1878 setl directory=
1879 unlet {a:vt}netrw_swfkeep
1880 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001881 if !g:netrw_use_noswf
1882 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1883 sil! let &l:swf= {a:vt}netrw_swfkeep
1884 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001885 unlet {a:vt}netrw_swfkeep
1886 endif
1887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001888 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001889 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1890 if exists("{a:vt}netrw_dirkeep")
1891 call s:NetrwLcd(dirkeep)
1892 unlet {a:vt}netrw_dirkeep
1893 endif
1894 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001895 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001896" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001897 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1898 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001899 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001900 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001901
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001902" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1903" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1904" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1905" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1906" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001907 " Moved the filetype detect here from NetrwGetFile() because remote files
1908 " were having their filetype detect-generated settings overwritten by
1909 " NetrwOptionRestore.
1910 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001911" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1912 filetype detect
1913" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001914 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001915" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001916" 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 +02001917" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001918endfun
1919
1920" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001921" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1922" but only when the options' value and the safe setting differ
1923" Doing this means that netrw will not come up as having changed a
1924" setting last when it really didn't actually change it.
1925"
1926" Called from s:NetrwOptionsSafe
1927" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1928fun! s:NetrwSetSafeSetting(setting,safesetting)
1929" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001930
Bram Moolenaar85850f32019-07-19 22:05:51 +02001931 if a:setting =~ '^&'
1932" call Decho("fyi: a:setting starts with &")
1933 exe "let settingval= ".a:setting
1934" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001935
Bram Moolenaar85850f32019-07-19 22:05:51 +02001936 if settingval != a:safesetting
1937" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1938 if type(a:safesetting) == 0
1939 exe "let ".a:setting."=".a:safesetting
1940 elseif type(a:safesetting) == 1
1941 exe "let ".a:setting."= '".a:safesetting."'"
1942 else
1943 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1944 endif
1945 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001946 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001947
Bram Moolenaar85850f32019-07-19 22:05:51 +02001948" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001949endfun
1950
1951" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001952" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1953" but only if the setting value differs from the associated keepvar.
1954" Doing this means that netrw will not come up as having changed a
1955" setting last when it really didn't actually change it.
1956"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001957" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001958" keepvars are set up by s:NetrwOptionsSave
1959fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001960""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001961
Bram Moolenaar85850f32019-07-19 22:05:51 +02001962 " typically called from s:NetrwOptionsRestore
1963 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1964 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001965 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966 if exists(a:keepvar)
1967 exe "let keepvarval= ".a:keepvar
1968 exe "let setting= ".a:setting
1969
1970"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1971"" call Decho("fyi: keepvarval=".keepvarval)
1972"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1973
1974 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001975"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001976 if type(a:setting) == 0
1977 exe "let ".a:setting."= ".keepvarval
1978 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001979 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001980 else
1981 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1982 endif
1983 endif
1984
1985 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001986 endif
1987
Bram Moolenaar85850f32019-07-19 22:05:51 +02001988"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001989endfun
1990
1991" ---------------------------------------------------------------------
1992" NetrwStatusLine: {{{2
1993fun! NetrwStatusLine()
1994
1995" vvv NetrwStatusLine() debugging vvv
1996" let g:stlmsg=""
1997" if !exists("w:netrw_explore_bufnr")
1998" let g:stlmsg="!X<explore_bufnr>"
1999" elseif w:netrw_explore_bufnr != bufnr("%")
2000" let g:stlmsg="explore_bufnr!=".bufnr("%")
2001" endif
2002" if !exists("w:netrw_explore_line")
2003" let g:stlmsg=" !X<explore_line>"
2004" elseif w:netrw_explore_line != line(".")
2005" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2006" endif
2007" if !exists("w:netrw_explore_list")
2008" let g:stlmsg=" !X<explore_list>"
2009" endif
2010" ^^^ NetrwStatusLine() debugging ^^^
2011
2012 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")
2013 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002014 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002015 let &laststatus = s:netrw_users_ls
2016 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2017 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2018 return ""
2019 else
2020 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2021 endif
2022endfun
2023
Bram Moolenaar85850f32019-07-19 22:05:51 +02002024" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002025" Netrw Transfer Functions: {{{1
2026" ===============================
2027
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002029" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002030" mode: =0 read remote file and insert before current line
2031" =1 read remote file and insert after current line
2032" =2 replace with remote file
2033" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002034fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002035" 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 +00002036
Bram Moolenaar5c736222010-01-06 20:54:52 +01002037 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002038 call s:NetrwOptionsSave("w:")
2039 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002040 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002041 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2042 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2043 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002044" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045
Bram Moolenaar5c736222010-01-06 20:54:52 +01002046 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002048 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 elseif a:mode == 2 " replace with remote file
2052 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002053 elseif a:mode == 3 " skip read of file (leave as temporary)
2054 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 else
2056 exe a:mode
2057 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002060" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061
Bram Moolenaar5c736222010-01-06 20:54:52 +01002062 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002063 let tmpfile= s:GetTempfile("")
2064 if tmpfile == ""
2065" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002066 return
2067 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002071 " attempt to repeat with previous host-file-etc
2072 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002073" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 let choice = b:netrw_lastfile
2075 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 else
2078 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002082 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002083 echomsg 'NetRead Usage:'
2084 echomsg ':Nread machine:path uses rcp'
2085 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2086 echomsg ':Nread "machine id password path" uses ftp'
2087 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2088 echomsg ':Nread fetch://machine/path uses fetch'
2089 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2090 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002091 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002092 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002093 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2094 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2095 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2096 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002097 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002098 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002099
Bram Moolenaar9964e462007-05-05 17:54:07 +00002100 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002101 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002102" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002105 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 else
2107 " case "... ... ..."
2108 let choice = strpart(choice,1,strlen(choice)-1)
2109 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002110
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 let wholechoice = wholechoice . " " . choice
2113 let ichoice = ichoice + 1
2114 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002115 if !exists("g:netrw_quiet")
2116 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2117 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002118" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 return
2120 endif
2121 let choice= a:{ichoice}
2122 endwhile
2123 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2124 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 endif
2126 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002128" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002129 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002130
Bram Moolenaar5c736222010-01-06 20:54:52 +01002131 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002132 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002133 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002134" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 return
2136 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002137 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002138
Bram Moolenaar8d043172014-01-23 14:24:41 +01002139 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002140" 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 +02002141 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002143 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002144" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002145 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002147
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002148 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002149 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002150 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002151 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2152 echo "(netrw) Processing your read request..."
2153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002154
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002156 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002158" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002159 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002161 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 " ER: the tmpfile is full path: rcp sees C:\... as host C
2163 if s:netrw_has_nt_rcp == 1
2164 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2165 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2166 else
2167 " Any way needed it machine contains a '.'
2168 let uid_machine = g:netrw_machine .'.'. $USERNAME
2169 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2172 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2173 else
2174 let uid_machine = g:netrw_machine
2175 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002177 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 +00002178 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002180
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002182 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002185 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002186 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002187 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002188 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002189 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002190" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002191 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002194 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002195 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002197 if exists("g:netrw_port") && g:netrw_port != ""
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)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 endif
2202 " 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 +00002203 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002204 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002205 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002206 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002207 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002209 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002210 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002211 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2212 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002213 q!
2214 endif
2215 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002216 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002218
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002220 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2222 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002223" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002225 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002226 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002227 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002229 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002230" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002232 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235
Bram Moolenaar97d62492012-11-15 21:28:22 +01002236 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002237 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002238 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002240 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002243" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002249
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002254 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002255 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002257 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 " perform ftp:
2262 " -i : turns off interactive prompting from ftp
2263 " -n unix : DON'T use <.netrc>, even though it exists
2264 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002265 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2268 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002270 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002271 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002272 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002274 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002275 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002277
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002279 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002281" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002283 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 else
2285 let useport= ""
2286 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002287 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2288 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002289 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002290 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2291 else
2292 let tmpfile_get = tmpfile
2293 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002294 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 +00002295 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002296 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002297
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002299 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002300 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002301" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002303 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002304 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002305 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002306" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002307 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002309
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002310 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2311 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002313 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314 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 +00002315 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316 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 +00002317 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002318 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002319
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002320 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002323 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2324 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2326" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2327 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 +00002328 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002330 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 endif
2332 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002334 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002335
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002336 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002337 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002338 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002339" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002340
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 if !executable(g:netrw_dav_cmd)
2342 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2343" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2344 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002346 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002347 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 +01002348 else
2349 " Construct execution string (four lines) which will be passed through filter
2350 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2351 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002352 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002354 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002358 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002359 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002360 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2362 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002363
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002365 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002366 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002367 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002369 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002370 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002372 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002374 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002376 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 +00002377 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002381 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002383 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002384" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002386 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002387 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002388 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002389" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002390 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002392 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 let netrw_option= "http"
2394 else
2395 let netrw_option= "ftp"
2396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002397" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002398
Bram Moolenaar446cb832008-06-24 21:56:24 +00002399 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
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_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402 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 +00002403 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaar446cb832008-06-24 21:56:24 +00002405 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002407" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002408 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002411 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002412 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2414 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 +00002415 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002419 " NetRead: (file) NetRead Method #10 {{{3
2420 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002421" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2422 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002423 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2424 let b:netrw_lastfile = choice
2425
2426 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002427 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002428 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002429 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 endif
2431 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002432
Bram Moolenaar5c736222010-01-06 20:54:52 +01002433 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002435" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 unlet b:netrw_fname
2438 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002439 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 +01002440" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002441 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002443 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002444
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446endfun
2447
2448" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002449" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002450fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002451" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002452
Bram Moolenaar5c736222010-01-06 20:54:52 +01002453 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002455 call s:NetrwOptionsSave("w:")
2456 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002457
Bram Moolenaar5c736222010-01-06 20:54:52 +01002458 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002459 let tmpfile= s:GetTempfile("")
2460 if tmpfile == ""
2461" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002462 return
2463 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 if a:0 == 0
2466 let ichoice = 0
2467 else
2468 let ichoice = 1
2469 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002470
Bram Moolenaar9964e462007-05-05 17:54:07 +00002471 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002472" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002473 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 " For binary writes, always write entire file.
2475 " (line numbers don't really make sense for that).
2476 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002477" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002478 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002479 elseif g:netrw_cygwin
2480 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002481 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002482" 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 +01002483 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002484 else
2485 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" 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 +01002487 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002488 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002489
Bram Moolenaar9964e462007-05-05 17:54:07 +00002490 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002491 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002492 " on the temporary file's name. Deletion of the temporary file during
2493 " cleanup then causes an error message.
2494 0file!
2495 endif
2496
Bram Moolenaar5c736222010-01-06 20:54:52 +01002497 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002498 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002499
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002501 " attempt to repeat with previous host-file-etc
2502 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002503" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 let choice = b:netrw_lastfile
2505 let ichoice= ichoice + 1
2506 else
2507 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002508
Bram Moolenaar8d043172014-01-23 14:24:41 +01002509 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002511 echomsg 'NetWrite Usage:"'
2512 echomsg ':Nwrite machine:path uses rcp'
2513 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2514 echomsg ':Nwrite "machine id password path" uses ftp'
2515 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2516 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2517 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2518 echomsg ':Nwrite rcp://machine/path uses rcp'
2519 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2520 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2521 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002522 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002523 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002524
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 elseif match(choice,"^\"") != -1
2526 if match(choice,"\"$") != -1
2527 " case "..."
2528 let choice=strpart(choice,1,strlen(choice)-2)
2529 else
2530 " case "... ... ..."
2531 let choice = strpart(choice,1,strlen(choice)-1)
2532 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002533
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 while match(choice,"\"$") == -1
2535 let wholechoice= wholechoice . " " . choice
2536 let ichoice = ichoice + 1
2537 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002538 if !exists("g:netrw_quiet")
2539 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2540 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002541" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 return
2543 endif
2544 let choice= a:{ichoice}
2545 endwhile
2546 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2547 endif
2548 endif
2549 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002550 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002551" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002552
Bram Moolenaar9964e462007-05-05 17:54:07 +00002553 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002554 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002555 if !exists("b:netrw_method") || b:netrw_method < 0
2556" call Dfunc("netrw#NetWrite : unsupported method")
2557 return
2558 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002559
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002560 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002561 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002562 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002563 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2564 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002565" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002566 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002570 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002571" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 if s:netrw_has_nt_rcp == 1
2573 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2574 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2575 else
2576 let uid_machine = g:netrw_machine .'.'. $USERNAME
2577 endif
2578 else
2579 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2580 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2581 else
2582 let uid_machine = g:netrw_machine
2583 endif
2584 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002585 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 +00002586 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002587
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002588 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002589 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002590 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002591" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002592 let netrw_fname = b:netrw_fname
2593
2594 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2595 let bhkeep = &l:bh
2596 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002597 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002601 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002602 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002604 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002605 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002607 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611 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 +00002612 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2614 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 endif
2616 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2617 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002618 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002619 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002620 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002621 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002623
2624 " remove enew buffer (quietly)
2625 let filtbuf= bufnr("%")
2626 exe curbuf."b!"
2627 let &l:bh = bhkeep
2628 exe filtbuf."bw!"
2629
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002631
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002633 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002634 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002635 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002636" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 let netrw_fname = b:netrw_fname
2638 let bhkeep = &l:bh
2639
2640 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2641 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002642 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002644 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002646 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002647 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002648" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002650 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002653 if exists("g:netrw_uid") && g:netrw_uid != ""
2654 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002655 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002657 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002665 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002668 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002671 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002674 " save choice/id/password for future use
2675 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002676
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 " perform ftp:
2678 " -i : turns off interactive prompting from ftp
2679 " -n unix : DON'T use <.netrc>, even though it exists
2680 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002681 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002682 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2684 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002685 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002686 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002687 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 let mod=1
2689 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002690
2691 " remove enew buffer (quietly)
2692 let filtbuf= bufnr("%")
2693 exe curbuf."b!"
2694 let &l:bh= bhkeep
2695 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002696
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002699 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002700" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002702 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 else
2704 let useport= ""
2705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706 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 +00002707 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002708
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002710 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002713 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2714 if executable(curl)
2715 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002716 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 +01002717 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002718 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002719 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002720
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002721 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002723 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002724" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002725
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002726 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002727 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2728 let bhkeep = &l:bh
2729
2730 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2731 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002732 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002733 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734
Bram Moolenaarff034192013-04-24 18:51:19 +02002735 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002737 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002738 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002739 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002741 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002742 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002743 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002745
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002747 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002749
2750 " remove enew buffer (quietly)
2751 let filtbuf= bufnr("%")
2752 exe curbuf."b!"
2753 let &l:bh = bhkeep
2754 exe filtbuf."bw!"
2755
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002756 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002757
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002758 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002759 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002760 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002761" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002762 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 +00002763 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002764
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002765 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002766 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002767 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002768" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002769 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2771 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2772 else
2773 let uid_machine = g:netrw_machine
2774 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002775
2776 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2777 let bhkeep = &l:bh
2778 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002779 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781
Bram Moolenaarff034192013-04-24 18:51:19 +02002782 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002784" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002785 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787 let filtbuf= bufnr("%")
2788 exe curbuf."b!"
2789 let &l:bh = bhkeep
2790 exe filtbuf."bw!"
2791 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002792
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002793 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002795 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002796 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002797 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002799 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002800
Bram Moolenaar5c736222010-01-06 20:54:52 +01002801 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002802" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002803 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002804" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002805 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002807 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002808
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002809 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002811 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" 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 +02002813 elseif !exists("leavemod")
2814 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002816 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" 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 +00002818 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002821endfun
2822
2823" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002824" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002825" uses NetRead to get a copy of the file into a temporarily file,
2826" then sources that file,
2827" then removes that file.
2828fun! netrw#NetSource(...)
2829" call Dfunc("netrw#NetSource() a:0=".a:0)
2830 if a:0 > 0 && a:1 == '?'
2831 " give help
2832 echomsg 'NetSource Usage:'
2833 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2834 echomsg ':Nsource fetch://machine/path uses fetch'
2835 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002836 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002837 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2838 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2839 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2840 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2841 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002842 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002844 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002849 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002851 if delete(s:netrw_tmpfile)
2852 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2853 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 unlet s:netrw_tmpfile
2855 else
2856 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2857 endif
2858 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002859 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 endif
2861" call Dret("netrw#NetSource")
2862endfun
2863
Bram Moolenaar8d043172014-01-23 14:24:41 +01002864" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002865" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2866" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002867fun! netrw#SetTreetop(iscmd,...)
2868" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2869" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002870
Bram Moolenaar85850f32019-07-19 22:05:51 +02002871 " iscmd==0: netrw#SetTreetop called using gn mapping
2872 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2873" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002874 " clear out the current tree
2875 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002876" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 let inittreetop= w:netrw_treetop
2878 unlet w:netrw_treetop
2879 endif
2880 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002881" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 unlet w:netrw_treedict
2883 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002884" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002885
Bram Moolenaar85850f32019-07-19 22:05:51 +02002886 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002887 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890 if isdirectory(s:NetrwFile(a:1))
2891" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002892 let treedir = a:1
2893 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = b:netrw_curdir."/".a:1
2896 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002897" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899 " normally the cursor is left in the message window.
2900 " However, here this results in the directory being listed in the message window, which is not wanted.
2901 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002902 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002904 let treedir = "."
2905 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 endif
2907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002909
2910 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911 let islocal= expand("%") !~ '^\a\{3,}://'
2912" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002913
2914 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002915 if islocal
2916 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2917 else
2918 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2919 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
Bram Moolenaara6878372014-03-22 21:02:50 +01002921" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002922endfun
2923
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002925" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926" readcmd == %r : replace buffer with newly read file
2927" == 0r : read file at top of buffer
2928" == r : read file after current line
2929" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002930fun! s:NetrwGetFile(readcmd, tfile, method)
2931" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932
2933 " readcmd=='t': simply do nothing
2934 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002935" 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 +01002936" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002937 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002938 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002939
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940 " get name of remote filename (ie. url and all)
2941 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002942" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 if exists("*NetReadFixup")
2945 " for the use of NetReadFixup (not otherwise used internally)
2946 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002947 endif
2948
Bram Moolenaar9964e462007-05-05 17:54:07 +00002949 if a:readcmd[0] == '%'
2950 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002951" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952
2953 " rename the current buffer to the temp file (ie. tfile)
2954 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002955 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 else
2957 let tfile= a:tfile
2958 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002959 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960
2961 " edit temporary file (ie. read the temporary file in)
2962 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002963" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 call zip#Browse(tfile)
2965 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002968 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002971 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002976 call tar#Browse(tfile)
2977 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002980 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002982 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002983 endif
2984
2985 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002986 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002987
Bram Moolenaar71badf92023-04-22 22:40:14 +01002988 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002989 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002990 " Note that isk must not include a "/" for scripts.vim
2991 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002992" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2993" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002994" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002995" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2996 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002997 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002998 filetype detect
2999" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003000 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003001" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003002 let line1 = 1
3003 let line2 = line("$")
3004
Bram Moolenaar8d043172014-01-23 14:24:41 +01003005 elseif !&ma
3006 " 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 +01003007 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003008" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003009 return
3010
Bram Moolenaar9964e462007-05-05 17:54:07 +00003011 elseif s:FileReadable(a:tfile)
3012 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003013" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003014 let curline = line(".")
3015 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003017 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003018 let line1= curline + 1
3019 let line2= line("$") - lastline + 1
3020
3021 else
3022 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003023" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3024" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003025 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003026" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003027 return
3028 endif
3029
3030 " User-provided (ie. optional) fix-it-up command
3031 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003032" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003033 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003034" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003035" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003036 endif
3037
Bram Moolenaaradc21822011-04-01 18:03:16 +02003038 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003039 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003040 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003041 endif
3042
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" 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 +00003044
3045 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003046" redraw!
3047
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003048" 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 +00003049" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003050endfun
3051
Bram Moolenaar9964e462007-05-05 17:54:07 +00003052" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003053" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003054" Input:
3055" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3056" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003057" b:netrw_method= 1: rcp
3058" 2: ftp + <.netrc>
3059" 3: ftp + machine, id, password, and [path]filename
3060" 4: scp
3061" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003062" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" 7: rsync
3064" 8: fetch
3065" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003066" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003067" g:netrw_machine= hostname
3068" b:netrw_fname = filename
3069" g:netrw_port = optional port number (for ftp)
3070" g:netrw_choice = copy of input url (choice)
3071fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003072" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003073
Bram Moolenaar251e1912011-06-19 05:09:16 +02003074 " sanity check: choice should have at least three slashes in it
3075 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3076 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3077 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003078" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003079 return
3080 endif
3081
Bram Moolenaar5c736222010-01-06 20:54:52 +01003082 " record current g:netrw_machine, if any
3083 " curmachine used if protocol == ftp and no .netrc
3084 if exists("g:netrw_machine")
3085 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003086" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003087 else
3088 let curmachine= "N O T A HOST"
3089 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003090 if exists("g:netrw_port")
3091 let netrw_port= g:netrw_port
3092 endif
3093
3094 " insure that netrw_ftp_cmd starts off every method determination
3095 " with the current g:netrw_ftp_cmd
3096 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003097
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 " initialization
3099 let b:netrw_method = 0
3100 let g:netrw_machine = ""
3101 let b:netrw_fname = ""
3102 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003103 let g:netrw_choice = a:choice
3104
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003106 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003107 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3108 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003109 " rcpurm : rcp://[user@]host/filename Use rcp
3110 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003112 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003113 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 " rsyncurm : rsync://host[:port]/path Use rsync
3115 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3116 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003117 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3119 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003120 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3121 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003123 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003124 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003125 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003129 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003130
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003131" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003133 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003135" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003136 let b:netrw_method = 1
3137 let userid = substitute(a:choice,rcpurm,'\1',"")
3138 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3139 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 if userid != ""
3141 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003143
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003147 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003148 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3149 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3150 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003151
Bram Moolenaar15146672011-10-20 22:22:38 +02003152 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003154" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 let b:netrw_method = 5
3156 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3157 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003158 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003159
Bram Moolenaaradc21822011-04-01 18:03:16 +02003160 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003164 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003165 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3166 else
3167 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3168 endif
3169 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003170
Bram Moolenaaradc21822011-04-01 18:03:16 +02003171 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003173" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 let b:netrw_method = 7
3175 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3176 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003177
Bram Moolenaaradc21822011-04-01 18:03:16 +02003178 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003180" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003181 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3183 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3184 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003185" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 if userid != ""
3187 let g:netrw_uid= userid
3188 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003189
Bram Moolenaaradc21822011-04-01 18:03:16 +02003190 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003191 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003192 call NetUserPass("ftp:".g:netrw_machine)
3193 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003194 " if there's a change in hostname, require password re-entry
3195 unlet s:netrw_passwd
3196 endif
3197 if exists("netrw_port")
3198 unlet netrw_port
3199 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003200 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003201
Bram Moolenaar446cb832008-06-24 21:56:24 +00003202 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003203 let b:netrw_method = 3
3204 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003205 let host= substitute(g:netrw_machine,'\..*$','','')
3206 if exists("s:netrw_hup[host]")
3207 call NetUserPass("ftp:".host)
3208
Nir Lichtman1e34b952024-05-08 19:19:34 +02003209 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003210" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3211" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003212 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003213 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003214" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003215 endif
3216 let b:netrw_method= 2
3217 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003219 let b:netrw_method= 2
3220 else
3221 if !exists("g:netrw_uid") || g:netrw_uid == ""
3222 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003223 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003224 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003225 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 endif
3227 let b:netrw_method= 3
3228 endif
3229 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003230
Bram Moolenaaradc21822011-04-01 18:03:16 +02003231 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003233" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 let b:netrw_method = 8
3235 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3236 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3237 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3238 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003239
Bram Moolenaaradc21822011-04-01 18:03:16 +02003240 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003244 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3245 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003246 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003248 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003249
Bram Moolenaaradc21822011-04-01 18:03:16 +02003250 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003251 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003252" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003253 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 let b:netrw_method = 3
3255 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3256 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003257
Bram Moolenaar9964e462007-05-05 17:54:07 +00003258 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 let b:netrw_method = 2
3260 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3261 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3262 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003263
Bram Moolenaaradc21822011-04-01 18:03:16 +02003264 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003266" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 let b:netrw_method = 9
3268 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3269 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003270
Bram Moolenaaradc21822011-04-01 18:03:16 +02003271 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003272 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003273" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003274 let b:netrw_method = 1
3275 let userid = substitute(a:choice,rcphf,'\2',"")
3276 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3277 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003278" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3279" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3280" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3281" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003282 if userid != ""
3283 let g:netrw_uid= userid
3284 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003285
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003286 " Method#10: file://user@hostname/...path-to-file {{{3
3287 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003288" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003289 let b:netrw_method = 10
3290 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003291" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003292
Bram Moolenaaradc21822011-04-01 18:03:16 +02003293 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003294 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003295 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003296 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003297 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003298 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003300 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003301
Bram Moolenaar81695252004-12-29 20:58:21 +00003302 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003303 " remove any leading [:#] from port number
3304 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3305 elseif exists("netrw_port")
3306 " retain port number as implicit for subsequent ftp operations
3307 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003308 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003309
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003310" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3311" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3312" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3313" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003314" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003315" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003316" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003317" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003319" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003320" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003321" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323
Bram Moolenaar9964e462007-05-05 17:54:07 +00003324" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003325" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003326" Usage: :call NetUserPass() -- will prompt for userid and password
3327" :call NetUserPass("uid") -- will prompt for password
3328" :call NetUserPass("uid","password") -- sets global userid and password
3329" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3330" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331fun! NetUserPass(...)
3332
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003333" call Dfunc("NetUserPass() a:0=".a:0)
3334
3335 if !exists('s:netrw_hup')
3336 let s:netrw_hup= {}
3337 endif
3338
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003340 " case: no input arguments
3341
3342 " change host and username if not previously entered; get new password
3343 if !exists("g:netrw_machine")
3344 let g:netrw_machine= input('Enter hostname: ')
3345 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003347 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 let g:netrw_uid= input('Enter username: ')
3349 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003350 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003351 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003352
3353 " set up hup database
3354 let host = substitute(g:netrw_machine,'\..*$','','')
3355 if !exists('s:netrw_hup[host]')
3356 let s:netrw_hup[host]= {}
3357 endif
3358 let s:netrw_hup[host].uid = g:netrw_uid
3359 let s:netrw_hup[host].passwd = s:netrw_passwd
3360
3361 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003362 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003363
3364 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003365 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003366 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003367" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003368 let host = substitute(a:1,'^ftp:','','')
3369 let host = substitute(host,'\..*','','')
3370 if exists("s:netrw_hup[host]")
3371 let g:netrw_uid = s:netrw_hup[host].uid
3372 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003373" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3374" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003375 else
3376 let g:netrw_uid = input("Enter UserId: ")
3377 let s:netrw_passwd = inputsecret("Enter Password: ")
3378 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003379
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003380 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003381 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003382" 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 +02003383 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003384 if g:netrw_machine =~ '[0-9.]\+'
3385 let host= g:netrw_machine
3386 else
3387 let host= substitute(g:netrw_machine,'\..*$','','')
3388 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003389 else
3390 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003391 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003392 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003393" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003394 if exists("g:netrw_passwd")
3395 " ask for password if one not previously entered
3396 let s:netrw_passwd= g:netrw_passwd
3397 else
3398 let s:netrw_passwd = inputsecret("Enter Password: ")
3399 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003400 endif
3401
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003402" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003403 if exists("host")
3404 if !exists('s:netrw_hup[host]')
3405 let s:netrw_hup[host]= {}
3406 endif
3407 let s:netrw_hup[host].uid = g:netrw_uid
3408 let s:netrw_hup[host].passwd = s:netrw_passwd
3409 endif
3410
3411 elseif a:0 == 2
3412 let g:netrw_uid = a:1
3413 let s:netrw_passwd = a:2
3414
3415 elseif a:0 == 3
3416 " enter hostname, user-id, and password into the hup dictionary
3417 let host = substitute(a:1,'^\a\+:','','')
3418 let host = substitute(host,'\..*$','','')
3419 if !exists('s:netrw_hup[host]')
3420 let s:netrw_hup[host]= {}
3421 endif
3422 let s:netrw_hup[host].uid = a:2
3423 let s:netrw_hup[host].passwd = a:3
3424 let g:netrw_uid = s:netrw_hup[host].uid
3425 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003426" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3427" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003429
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003430" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432
Bram Moolenaar85850f32019-07-19 22:05:51 +02003433" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003434" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003435" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003437" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003438" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3439fun! s:ExplorePatHls(pattern)
3440" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3441 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003442" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003443 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003444" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003445 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3446" call Dret("s:ExplorePatHls repat<".repat.">")
3447 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003448endfun
3449
3450" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003451" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003452" 0: (user: <mb>) bookmark current directory
3453" 1: (user: <gb>) change to the bookmarked directory
3454" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003455" 3: (browsing) records current directory history
3456" 4: (user: <u>) go up (previous) directory, using history
3457" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003458" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003459fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003460" 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 +02003461 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3462" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3463 return
3464 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003466 let ykeep = @@
3467 let curbufnr = bufnr("%")
3468
Bram Moolenaar9964e462007-05-05 17:54:07 +00003469 if a:chg == 0
3470 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003471" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003472 if exists("s:netrwmarkfilelist_{curbufnr}")
3473 call s:NetrwBookmark(0)
3474 echo "bookmarked marked files"
3475 else
3476 call s:MakeBookmark(a:curdir)
3477 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003478 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003479
KSR-Yasudaf4498252023-10-06 03:34:17 +09003480 try
3481 call s:NetrwBookHistSave()
3482 catch
3483 endtry
3484
Bram Moolenaar9964e462007-05-05 17:54:07 +00003485 elseif a:chg == 1
3486 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003487" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003488 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003489" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003490 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491 else
3492 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3493 endif
3494
3495 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003496" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003497 let didwork= 0
3498 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003499" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003500 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003501" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003502 let cnt= 1
3503 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003505 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003506 let didwork = 1
3507 let cnt = cnt + 1
3508 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003509 endif
3510
3511 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003512 " Note: history is saved only when PerformListing is done;
3513 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3514 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003515 let first = 1
3516 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003517 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003518 while ( first || cnt != g:netrw_dirhistcnt )
3519" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003520 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003521" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003522 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003523 let didwork= 1
3524 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003525 let histcnt = histcnt + 1
3526 let first = 0
3527 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if cnt < 0
3529 let cnt= cnt + g:netrw_dirhistmax
3530 endif
3531 endwhile
3532 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003533 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003534 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003535 if didwork
3536 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3537 endif
3538
3539 elseif a:chg == 3
3540 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003541" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003542 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 +02003543 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003544 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3545 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003546 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003547" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003548 endif
3549
3550 elseif a:chg == 4
3551 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003552" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003553 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3555 if g:netrw_dirhistcnt < 0
3556 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 endif
3558 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003560 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3562" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003563 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003564 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003565" call Decho("setl ma noro",'~'.expand("<slnum>"))
3566 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003567 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003568" call Decho("setl nomod",'~'.expand("<slnum>"))
3569" 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 +00003570 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003571" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3572 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003573 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003576 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003579 echo "Sorry, no predecessor directory exists yet"
3580 endif
3581
3582 elseif a:chg == 5
3583 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003584" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003585 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003586 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3587 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3588" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003589 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003590" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003591 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592 sil! NetrwKeepj %d _
3593" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3594" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003595 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003596" 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 +02003597 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003598" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3599 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003600 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3602 if g:netrw_dirhistcnt < 0
3603 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003604 endif
3605 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003606 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003607 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003608 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003609 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003610 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003611
3612 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003613" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003614 if exists("s:netrwmarkfilelist_{curbufnr}")
3615 call s:NetrwBookmark(1)
3616 echo "removed marked files from bookmarks"
3617 else
3618 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003619 let iremove = v:count
3620 let dremove = g:netrw_bookmarklist[iremove - 1]
3621" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003622 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003623" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3624 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3625 echo "removed ".dremove." from g:netrw_bookmarklist"
3626" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003627 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003628" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003629
3630 try
3631 call s:NetrwBookHistSave()
3632 catch
3633 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003634 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003635 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003636 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003637 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003638" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003639endfun
3640
3641" ---------------------------------------------------------------------
3642" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003643" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003644" Sister function: s:NetrwBookHistSave()
3645fun! s:NetrwBookHistRead()
3646" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003647 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003648" 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 +02003649 return
3650 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003651 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003652
3653 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003654 if !exists("s:netrw_initbookhist")
3655 let home = s:NetrwHome()
3656 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003657 if filereadable(s:NetrwFile(savefile))
3658" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003659 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003660 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003661
3662 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003663 if g:netrw_dirhistmax > 0
3664 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003665 if filereadable(s:NetrwFile(savefile))
3666" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003667 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003668 endif
3669 let s:netrw_initbookhist= 1
3670 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003672 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003673
Bram Moolenaar97d62492012-11-15 21:28:22 +01003674 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003675" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3676" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003677" call Dret("s:NetrwBookHistRead")
3678endfun
3679
3680" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682" Sister function: s:NetrwBookHistRead()
3683" I used to do this via viminfo but that appears to
3684" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003685" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3686" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003687" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003690 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003692 return
3693 endif
3694
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003698
3699 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003701" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003702 if g:netrw_use_noswf
3703 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3704 else
3705 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3706 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003707 setl nocin noai noci magic nospell nohid wig= noaw
3708 setl ma noro write
3709 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003710 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712 " rename enew'd file: .netrwhist -- no attempt to merge
3713 " record dirhistmax and current dirhistcnt
3714 " save history
3715" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003716 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003717 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003718 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3719 if g:netrw_dirhistmax > 0
3720 let lastline = line("$")
3721 let cnt = g:netrw_dirhistcnt
3722 let first = 1
3723 while ( first || cnt != g:netrw_dirhistcnt )
3724 let lastline= lastline + 1
3725 if exists("g:netrw_dirhist_{cnt}")
3726 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3727" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3728 endif
3729 let first = 0
3730 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3731 if cnt < 0
3732 let cnt= cnt + g:netrw_dirhistmax
3733 endif
3734 endwhile
3735 exe "sil! w! ".savefile
3736" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3737 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003738
Bram Moolenaar85850f32019-07-19 22:05:51 +02003739 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003740 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003742" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743 " merge and write .netrwbook
3744 let savefile= s:NetrwHome()."/.netrwbook"
3745
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003746 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003748 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749 for bdm in booklist
3750 if index(g:netrw_bookmarklist,bdm) == -1
3751 call add(g:netrw_bookmarklist,bdm)
3752 endif
3753 endfor
3754 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 endif
3756
3757 " construct and save .netrwbook
3758 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003759 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003760" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003762
3763 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003764 let bgone= bufnr("%")
3765 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003766 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003767
3768" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003769endfun
3770
3771" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003772" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3773" list of the contents of a local or remote directory. It is assumed that the
3774" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3775" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003776" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003777fun! s:NetrwBrowse(islocal,dirname)
3778 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003779" 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 +02003780" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3781" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3782" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003783
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003784 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3785 " This is useful when one edits a local file, then :e ., then :Rex
3786 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3787 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003788" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003789 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003790
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003791 " s:NetrwBrowse : initialize history {{{3
3792 if !exists("s:netrw_initbookhist")
3793 NetrwKeepj call s:NetrwBookHistRead()
3794 endif
3795
3796 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003797 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003798 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003799" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800 else
3801 let dirname= a:dirname
3802 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003803
Bram Moolenaar85850f32019-07-19 22:05:51 +02003804 " repoint t:netrw_lexbufnr if appropriate
3805 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3806" call Decho("set repointlexbufnr to true!")
3807 let repointlexbufnr= 1
3808 endif
3809
3810 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003811 if exists("s:netrw_skipbrowse")
3812 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003813" 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 +01003814" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815 return
3816 endif
3817 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003818 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819" call Dret("s:NetrwBrowse : missing shellescape()")
3820 return
3821 endif
3822 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003823 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824" call Dret("s:NetrwBrowse : missing fnameescape()")
3825 return
3826 endif
3827
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003828 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003829 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003832 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3833 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3834" call Decho("clearing marked files",'~'.expand("<slnum>"))
3835 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3836 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003837 endif
3838
3839 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003840 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003841" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3842" 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 +02003843 if s:NetrwLcd(dirname)
3844" call Dret("s:NetrwBrowse : lcd failure")
3845 return
3846 endif
3847 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003848" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003849
Bram Moolenaar5c736222010-01-06 20:54:52 +01003850 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003853 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003856 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003858" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859
3860 " remove any filetype indicator from end of dirname, except for the
3861 " "this is a directory" indicator (/).
3862 " There shouldn't be one of those here, anyway.
3863 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003864" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 call s:RemotePathAnalysis(dirname)
3866
3867 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3868 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003869 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 let b:netrw_curdir = dirname
3873 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003874 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3876 sil call netrw#NetRead(2,url)
3877 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003878" call Decho("url<".url.">",'~'.expand("<slnum>"))
3879" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3880" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 if s:path =~ '.bz2'
3882 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3883 elseif s:path =~ '.gz'
3884 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3885 elseif s:path =~ '.gz'
3886 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3887 else
3888 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3889 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003890 endif
3891
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003892 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003894 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003896 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003897" 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 +00003898
Bram Moolenaar446cb832008-06-24 21:56:24 +00003899" call Dret("s:NetrwBrowse : file<".s:fname.">")
3900 return
3901 endif
3902
Bram Moolenaaradc21822011-04-01 18:03:16 +02003903 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 call s:UseBufWinVars()
3905
3906 " set up some variables {{{3
3907 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003908 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003909 let s:last_sort_by = g:netrw_sort_by
3910
3911 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003912 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913
Bram Moolenaar97d62492012-11-15 21:28:22 +01003914 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003915" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003916 let svpos = winsaveview()
3917" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003918 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003921 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3922 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3923" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3924" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3925 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3926 else
3927" " call Decho("2match none",'~'.expand("<slnum>"))
3928 2match none
3929 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003930 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003931 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003933" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003934 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" 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 +01003936" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937 return
3938 endif
3939
3940 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003942 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003943 if b:netrw_curdir =~ '[/\\]$'
3944 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3945 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003946 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003947 let b:netrw_curdir= b:netrw_curdir."/"
3948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 if b:netrw_curdir == ''
3950 if has("amiga")
3951 " On the Amiga, the empty string connotes the current directory
3952 let b:netrw_curdir= getcwd()
3953 else
3954 " under unix, when the root directory is encountered, the result
3955 " from the preceding substitute is an empty string.
3956 let b:netrw_curdir= '/'
3957 endif
3958 endif
3959 if !a:islocal && b:netrw_curdir !~ '/$'
3960 let b:netrw_curdir= b:netrw_curdir.'/'
3961 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003962" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003963
3964 " ------------
3965 " (local only) {{{3
3966 " ------------
3967 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003969
3970 " Set up ShellCmdPost handling. Append current buffer to browselist
3971 call s:LocalFastBrowser()
3972
3973 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3974 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003975" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3976" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003977 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003978 if s:NetrwLcd(b:netrw_curdir)
3979" call Dret("s:NetrwBrowse : lcd failure")
3980 return
3981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003982 endif
3983 endif
3984
3985 " --------------------------------
3986 " remote handling: {{{3
3987 " --------------------------------
3988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003989" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990
Bram Moolenaar97d62492012-11-15 21:28:22 +01003991 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992" 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 +02003993 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3997 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3998 if dirname !~ '/$'
3999 let dirname= dirname.'/'
4000 endif
4001 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004002" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004003 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004004 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 endif
4007
4008 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4009 if dirname !~ dirpat
4010 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004011 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004012 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004013 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004014" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004015 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" 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 +00004017" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4018 return
4019 endif
4020 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004021" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004022 endif " (additional remote handling)
4023
Bram Moolenaar85850f32019-07-19 22:05:51 +02004024 " -------------------------------
4025 " Perform Directory Listing: {{{3
4026 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004027 NetrwKeepj call s:NetrwMaps(a:islocal)
4028 NetrwKeepj call s:NetrwCommands(a:islocal)
4029 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004031 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004033" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4034
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004035 " If there is a rexposn: restore position with rexposn
4036 " Otherwise : set rexposn
4037 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004038" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4039 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4040 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4041 NetrwKeepj exe w:netrw_bannercnt
4042 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043 else
4044 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4045 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004046 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004047 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004048" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004049 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004050 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004051
Bram Moolenaar85850f32019-07-19 22:05:51 +02004052 " repoint t:netrw_lexbufnr if appropriate
4053 if exists("repointlexbufnr")
4054 let t:netrw_lexbufnr= bufnr("%")
4055" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4056 endif
4057
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004058 " restore position
4059 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004060" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4061 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004062 endif
4063
Bram Moolenaara6878372014-03-22 21:02:50 +01004064 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004065 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4066 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004067" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4068" 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 +02004069" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004070 return
4071endfun
4072
4073" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4075" may not apply correctly; ie. netrw's idea of the current directory may
4076" differ from vim's. This function insures that netrw's idea of the current
4077" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004078" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4081" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4082" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4083" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4084" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004085
4086 " clean up any leading treedepthstring
4087 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4088 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004089" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004090 else
4091 let fname= a:fname
4092 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004093
4094 if g:netrw_keepdir
4095 " vim's idea of the current directory possibly may differ from netrw's
4096 if !exists("b:netrw_curdir")
4097 let b:netrw_curdir= getcwd()
4098 endif
4099
Nir Lichtman1e34b952024-05-08 19:19:34 +02004100 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004103 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004104" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105 else
4106 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004107 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004108" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109 endif
4110
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004111 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004114" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115 else
4116 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119 endif
4120 else
4121 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004122 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004123" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4124" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4125" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126 endif
4127
Bram Moolenaar85850f32019-07-19 22:05:51 +02004128" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004129 return ret
4130endfun
4131
4132" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004133" s:NetrwFileInfo: supports qf (query for file information) {{{2
4134fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004135" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004136 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004137 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004138 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004139 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004140 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004141 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 let lsopt= "-lsadh --si"
4143 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004144" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004145 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004146
4147 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004148 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004149" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004150
Bram Moolenaara6878372014-03-22 21:02:50 +01004151 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004152 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004154
4155 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004158
Bram Moolenaar446cb832008-06-24 21:56:24 +00004159 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004161 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004163 endif
4164 else
4165 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4167 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004168 let fname= substitute(a:fname,".$","","")
4169 else
4170 let fname= a:fname
4171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172 let t = getftime(s:NetrwFile(fname))
4173 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004174 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004175 let sz= s:NetrwHumanReadable(sz)
4176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004177 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4178" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 endif
4180 else
4181 echo "sorry, \"qf\" not supported yet for remote files"
4182 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004183 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004184" call Dret("s:NetrwFileInfo")
4185endfun
4186
4187" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004188" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4189fun! s:NetrwFullPath(filename)
4190" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4191 let filename= a:filename
4192 if filename !~ '^/'
4193 let filename= resolve(getcwd().'/'.filename)
4194 endif
4195 if filename != "/" && filename =~ '/$'
4196 let filename= substitute(filename,'/$','','')
4197 endif
4198" " call Dret("s:NetrwFullPath <".filename.">")
4199 return filename
4200endfun
4201
4202" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004203" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004204" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004205" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004206" 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 +00004207fun! s:NetrwGetBuffer(islocal,dirname)
4208" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004209" 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 +02004210" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4211" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212 let dirname= a:dirname
4213
4214 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004215" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004216 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004217" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004218 let s:netrwbuf= {}
4219 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004220" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4221" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4222
4223 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4224 let bufnum = -1
4225
4226 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4227 if has_key(s:netrwbuf,"NetrwTreeListing")
4228 let bufnum= s:netrwbuf["NetrwTreeListing"]
4229 else
4230 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4231 endif
4232" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4233 if !bufexists(bufnum)
4234 call remove(s:netrwbuf,"NetrwTreeListing"])
4235 let bufnum= -1
4236 endif
4237 elseif bufnr("NetrwTreeListing") != -1
4238 let bufnum= bufnr("NetrwTreeListing")
4239" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4240 else
4241" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4242 let bufnum= -1
4243 endif
4244
4245 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004246 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004247" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004248 if !bufexists(bufnum)
4249 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4250 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004251 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004252
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004254" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004255 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004257" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4258
Bram Moolenaar71badf92023-04-22 22:40:14 +01004259 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004260 " IF the buffer already has the desired name
4261 " AND it is empty
4262 let curbuf = bufname("%")
4263 if curbuf == '.'
4264 let curbuf = getcwd()
4265 endif
4266" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004267" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004268" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4269" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4270" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4271" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4272 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004273" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4274 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004275 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004276" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004277 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004278 " 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 +00004279
4280 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004281 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004282" 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 +00004283 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004284" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004285 " name the buffer
4286 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4287 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004289 let w:netrw_treebufnr = bufnr("%")
4290 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004291 if g:netrw_use_noswf
4292 setl nobl bt=nofile noswf
4293 else
4294 setl nobl bt=nofile
4295 endif
4296 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4297 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4298 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4299 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004300" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004302 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004303 " enter the new buffer into the s:netrwbuf dictionary
4304 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4305" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4306" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004308" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309
4310 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004312 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004314 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004315
4316 if &ft == "netrw"
4317" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4318 exe "sil! NetrwKeepj noswapfile b ".bufnum
4319" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004321" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4322 call s:NetrwEditBuf(bufnum)
4323" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004325" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004327 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004329
4330 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004332
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004333 if line("$") <= 1 && getline(1) == ""
4334 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336" 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>"))
4337" 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 +01004338" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4339 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004340
Bram Moolenaar97d62492012-11-15 21:28:22 +01004341 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004342" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344 sil NetrwKeepj %d _
4345" 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>"))
4346" 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 +01004347" 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 +00004348 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004349
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4352" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004353 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004355 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356" 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>"))
4357" 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 +01004358" 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 +00004359 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004360
Bram Moolenaar446cb832008-06-24 21:56:24 +00004361 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" 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>"))
4363" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4364" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 return 1
4366 endif
4367 endif
4368
4369 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4370 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4371 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4372 " med 1 D H
4373 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004374" 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 +00004375 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004376 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004377 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378
4379 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4381" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4382 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004383
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004384" 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>"))
4385" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4386" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387 return 0
4388endfun
4389
4390" ---------------------------------------------------------------------
4391" s:NetrwGetcwd: get the current directory. {{{2
4392" Change backslashes to forward slashes, if any.
4393" If doesc is true, escape certain troublesome characters
4394fun! s:NetrwGetcwd(doesc)
4395" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4396 let curdir= substitute(getcwd(),'\\','/','ge')
4397 if curdir !~ '[\/]$'
4398 let curdir= curdir.'/'
4399 endif
4400 if a:doesc
4401 let curdir= fnameescape(curdir)
4402 endif
4403" call Dret("NetrwGetcwd <".curdir.">")
4404 return curdir
4405endfun
4406
4407" ---------------------------------------------------------------------
4408" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4409fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004410" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4411" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4412 let keepsol= &l:sol
4413 setl nosol
4414
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 call s:UseBufWinVars()
4416
4417 " insure that w:netrw_liststyle is set up
4418 if !exists("w:netrw_liststyle")
4419 if exists("g:netrw_liststyle")
4420 let w:netrw_liststyle= g:netrw_liststyle
4421 else
4422 let w:netrw_liststyle= s:THINLIST
4423 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425 endif
4426
4427 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4428 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004429" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004430 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 let dirname= "./"
4432 let curline= getline('.')
4433
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004434 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004435 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436 let s:netrw_skipbrowse= 1
4437 echo 'Pressing "s" also works'
4438
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004439 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let s:netrw_skipbrowse= 1
4441 echo 'Press "S" to edit sorting sequence'
4442
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004443 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004444 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004447 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004448 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449 let s:netrw_skipbrowse= 1
4450 echo 'Pressing "a" also works'
4451
4452 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004453 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454 endif
4455
4456 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004457" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004458 NetrwKeepj norm! 0
4459 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460
4461 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004462" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004463 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004464 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4465
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004466 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004468 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004469 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004470
4471 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004472" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473 let dirname= getline('.')
4474
4475 if !exists("b:netrw_cpf")
4476 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004477 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 +01004478 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004479" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004480 endif
4481
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004482" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004484" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4485" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004487 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 else
4489 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004490 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 endif
Enno3146d632024-07-04 19:44:42 +02004492
4493 let dict={}
4494 " save the unnamed register and register 0-9 and a
4495 let dict.a=[getreg('a'), getregtype('a')]
4496 for i in range(0, 9)
4497 let dict[i] = [getreg(i), getregtype(i)]
4498 endfor
4499 let dict.unnamed = [getreg(''), getregtype('')]
4500
Bram Moolenaarc236c162008-07-13 17:41:49 +00004501 let eofname= filestart + b:netrw_cpf + 1
4502 if eofname <= col("$")
4503 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004507 endif
Enno3146d632024-07-04 19:44:42 +02004508
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004510 call s:RestoreRegister(dict)
4511
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004514" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004515 endif
4516
4517 " symlinks are indicated by a trailing "@". Remove it before further processing.
4518 let dirname= substitute(dirname,"@$","","")
4519
4520 " executables are indicated by a trailing "*". Remove it before further processing.
4521 let dirname= substitute(dirname,"\*$","","")
4522
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523 let &l:sol= keepsol
4524
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525" call Dret("s:NetrwGetWord <".dirname.">")
4526 return dirname
4527endfun
4528
4529" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004530" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4531" g:netrw_bufsettings will be used after the listing is produced.
4532" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004533fun! s:NetrwListSettings(islocal)
4534" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004535" 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 +00004536 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004537" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4538 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4539 setl bt=nofile nobl ma nonu nowrap noro nornu
4540 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004542 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004544" call Dredir("ls!","s:NetrwListSettings")
4545" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004546 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004547 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004549 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004551 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004553" 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 +00004554" call Dret("s:NetrwListSettings")
4555endfun
4556
4557" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004558" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559" islocal=0: remote browsing
4560" =1: local browsing
4561fun! s:NetrwListStyle(islocal)
4562" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004563
Bram Moolenaar97d62492012-11-15 21:28:22 +01004564 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565 let fname = s:NetrwGetWord()
4566 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004567 let svpos = winsaveview()
4568" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004570" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4571" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4572" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573
Bram Moolenaar85850f32019-07-19 22:05:51 +02004574 " repoint t:netrw_lexbufnr if appropriate
4575 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4576" call Decho("set repointlexbufnr to true!")
4577 let repointlexbufnr= 1
4578 endif
4579
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 if w:netrw_liststyle == s:THINLIST
4581 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4584
4585 elseif w:netrw_liststyle == s:LONGLIST
4586 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4589
4590 elseif w:netrw_liststyle == s:WIDELIST
4591 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004592" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4594
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004595 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004596" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4598
4599 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004600 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601 let g:netrw_liststyle = s:THINLIST
4602 let w:netrw_liststyle = g:netrw_liststyle
4603 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4604 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004605 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004606" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607
4608 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4610 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004611 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004613 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004614" 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 +00004615
4616 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004618 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004619 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004620
Bram Moolenaar85850f32019-07-19 22:05:51 +02004621 " repoint t:netrw_lexbufnr if appropriate
4622 if exists("repointlexbufnr")
4623 let t:netrw_lexbufnr= bufnr("%")
4624" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4625 endif
4626
Bram Moolenaar13600302014-05-22 18:26:40 +02004627 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4629 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004630 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631
4632" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4633endfun
4634
4635" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004636" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4637fun! s:NetrwBannerCtrl(islocal)
4638" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4639
Bram Moolenaar97d62492012-11-15 21:28:22 +01004640 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004641 " toggle the banner (enable/suppress)
4642 let g:netrw_banner= !g:netrw_banner
4643
4644 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004645 let svpos= winsaveview()
4646" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004647 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4648
4649 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004650 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4651 let fname= s:NetrwGetWord()
4652 sil NetrwKeepj $
4653 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4654" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4655 if result <= 0 && exists("w:netrw_bannercnt")
4656 exe "NetrwKeepj ".w:netrw_bannercnt
4657 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004658 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004659 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004660" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4661endfun
4662
4663" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004664" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4665"
4666" No bang: enters files/directories into Netrw's bookmark system
4667" No argument and in netrw buffer:
4668" if there are marked files: bookmark marked files
4669" otherwise : bookmark file/directory under cursor
4670" No argument and not in netrw buffer: bookmarks current open file
4671" Has arguments: globs them individually and bookmarks them
4672"
4673" With bang: deletes files/directories from Netrw's bookmark system
4674fun! s:NetrwBookmark(del,...)
4675" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4676 if a:0 == 0
4677 if &ft == "netrw"
4678 let curbufnr = bufnr("%")
4679
4680 if exists("s:netrwmarkfilelist_{curbufnr}")
4681 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004682" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004683 let svpos = winsaveview()
4684" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004685 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004686 for fname in s:netrwmarkfilelist_{curbufnr}
4687 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4688 endfor
4689 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4690 call s:NetrwUnmarkList(curbufnr,curdir)
4691 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004692" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4693 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004694 else
4695 let fname= s:NetrwGetWord()
4696 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4697 endif
4698
4699 else
4700 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004701" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 let fname= expand("%")
4703 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4704 endif
4705
4706 else
4707 " bookmark specified files
4708 " attempts to infer if working remote or local
4709 " by deciding if the current file begins with an url
4710 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004711 let islocal= expand("%") !~ '^\a\{3,}://'
4712" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004713 let i = 1
4714 while i <= a:0
4715 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004716 if v:version > 704 || (v:version == 704 && has("patch656"))
4717 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004719 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 else
4722 let mbfiles= [a:{i}]
4723 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004726" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004727 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4728 endfor
4729 let i= i + 1
4730 endwhile
4731 endif
4732
4733 " update the menu
4734 call s:NetrwBookmarkMenu()
4735
4736" call Dret("s:NetrwBookmark")
4737endfun
4738
4739" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4741" .2.[cnt] for bookmarks, and
4742" .3.[cnt] for history
4743" (see s:NetrwMenu())
4744fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004745 if !exists("s:netrw_menucnt")
4746 return
4747 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004748" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004749
4750 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004751 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004753" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004754 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4755 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004756 endif
4757 if !exists("s:netrw_initbookhist")
4758 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004759 endif
4760
4761 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004762 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004763 let cnt= 1
4764 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004765" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004766 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004767
4768 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004769 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004770
4771 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004772 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 +01004773 let cnt= cnt + 1
4774 endfor
4775
4776 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777
4778 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 let first = 1
4782 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004785 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004786 if exists("g:netrw_dirhist_{cnt}")
4787 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004788" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004789 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4790 endif
4791 let first = 0
4792 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4793 if cnt < 0
4794 let cnt= cnt + g:netrw_dirhistmax
4795 endif
4796 endwhile
4797 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004798
Bram Moolenaar9964e462007-05-05 17:54:07 +00004799 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004800" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004801endfun
4802
4803" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4805" directory and a new directory name. Also, if the
4806" "new directory name" is actually a file,
4807" NetrwBrowseChgDir() edits the file.
4808fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004809" 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 +01004810" 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 +00004811
Bram Moolenaar97d62492012-11-15 21:28:22 +01004812 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813 if !exists("b:netrw_curdir")
4814 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4815 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004816 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004817" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4818" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004819" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004821 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004823" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004824
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004825 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004827 call s:SavePosn(s:netrw_posn)
4828 NetrwKeepj call s:NetrwOptionsSave("s:")
4829 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004830 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004831 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004832 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004833 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004834 endif
4835 let newdir = a:newdir
4836 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004837 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004838" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004839" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004840" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004841
4842 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004843" 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 +01004844 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004845" 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 +01004846 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004847 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" 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 +01004849 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" 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 +02004851 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004852 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004853 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004854 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004855" 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 +01004856 endif
4857 endif
4858" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004859" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004860 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004861
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 " set up o/s-dependent directory recognition pattern
4863 if has("amiga")
4864 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004865 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 let dirpat= '[\/]$'
4867 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004868" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869
4870 if dirname !~ dirpat
4871 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004872 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004874" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 endif
4876
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004877" 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 +01004878 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004879 " ------------------------------
4880 " NetrwBrowseChgDir: edit a file {{{3
4881 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004882" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004883
Bram Moolenaar97d62492012-11-15 21:28:22 +01004884 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004885 let s:rexposn_{bufnr("%")}= winsaveview()
4886" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4888" 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 +01004889
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004891" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4892" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004893" let newdir = s:NetrwTreePath(s:netrw_treetop)
4894" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004895 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004896 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4897" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4898 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 if dirname =~ '/$'
4900 let dirname= dirname.newdir
4901 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004902 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004904" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4905" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004907" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004909 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004912" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004913 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004915" 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 +02004916 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004917 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004919" " 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 +01004920 if type(g:netrw_browse_split) == 3
4921 " open file in server
4922 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004924 call s:NetrwServerEdit(a:islocal,dirname)
4925" call Dret("s:NetrwBrowseChgDir")
4926 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004927
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004928 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004929 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004930" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004931 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4932 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004933 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004934 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004935 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004936 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004937
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004939 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004940" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004941 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4942 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004943 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004944 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004945 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004946 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004947
Bram Moolenaar446cb832008-06-24 21:56:24 +00004948 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004949 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004950" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004951 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004952 if !exists("b:netrw_curdir")
4953 let b:netrw_curdir= getcwd()
4954 endif
4955 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004956
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004958 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004959" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004961 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004962" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004963 return
4964 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004965 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004966
Bram Moolenaar9964e462007-05-05 17:54:07 +00004967 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004969" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004970 call s:NetrwMenu(0)
4971 " optional change to window
4972 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004973" 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 +02004974 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004975 " if g:netrw_chgwin is set to one more than the last window, then
4976 " vertically split the last window to make that window available.
4977 let curwin= winnr()
4978 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4979 vs
4980 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004981 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004982 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004983 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004984 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004985 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004986
Bram Moolenaar9964e462007-05-05 17:54:07 +00004987 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004988
Bram Moolenaar446cb832008-06-24 21:56:24 +00004989 " the point where netrw actually edits the (local) file
4990 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004991 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004992 if !&mod
4993 " if e the new file would fail due to &mod, then don't change any of the flags
4994 let dolockout= 1
4995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004996 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004997" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004998 " some like c-^ to return to the last edited file
4999 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005000 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5001 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005002 call s:NetrwEditFile("e","",dirname)
5003" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005004 " COMBAK -- cuc cul related
5005 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005006 if &hidden || &bufhidden == "hide"
5007 " file came from vim's hidden storage. Don't "restore" options with it.
5008 let dorestore= 0
5009 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005010 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005011" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005012 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005013
5014 " handle g:Netrw_funcref -- call external-to-netrw functions
5015 " This code will handle g:Netrw_funcref as an individual function reference
5016 " or as a list of function references. It will ignore anything that's not
5017 " a function reference. See :help Funcref for information about function references.
5018 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005020 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005021" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005022 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005024" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005025 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005026 if type(Fncref) == 2
5027 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005028 endif
5029 endfor
5030 endif
5031 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005032 endif
5033
5034 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005035 " ----------------------------------------------------
5036 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5037 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005039 let dirname = newdir
5040 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005041 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005043
5044 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005045 " ---------------------------------------------
5046 " NetrwBrowseChgDir: refresh the directory list {{{3
5047 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005048" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005049 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005050 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005051
5052 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005053 " --------------------------------------
5054 " NetrwBrowseChgDir: go up one directory {{{3
5055 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005056" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005057
5058 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5059 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005060" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5061" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005062 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005063 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005064 endif
5065
5066 if has("amiga")
5067 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005068" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005069 if a:islocal
5070 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5071 let dirname= substitute(dirname,'/$','','')
5072 else
5073 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005075" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005076
Nir Lichtman1e34b952024-05-08 19:19:34 +02005077 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005078 " windows
5079 if a:islocal
5080 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5081 if dirname == ""
5082 let dirname= '/'
5083 endif
5084 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005085 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005086 endif
5087 if dirname =~ '^\a:$'
5088 let dirname= dirname.'/'
5089 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005090" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005091
Bram Moolenaar446cb832008-06-24 21:56:24 +00005092 else
5093 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005094" 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 +00005095 if a:islocal
5096 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5097 if dirname == ""
5098 let dirname= '/'
5099 endif
5100 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005101 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005103" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005104 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005105 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005106 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005107
5108 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005109 " --------------------------------------
5110 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5111 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005112" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5114" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005115 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5118 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005119 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005120 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005122 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005123 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005124" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125
5126 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005127" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005129" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 let haskey= 1
5131 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005132" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 endif
5134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005136" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005137 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 if has_key(w:netrw_treedict,treedir."/")
5139 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 let haskey = 1
5142 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 endif
5145 endif
5146
5147 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005148" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 if !haskey && treedir =~ '/$'
5150 let treedir= substitute(treedir,'/$','','')
5151 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005152" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 let haskey = 1
5154 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005155" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 endif
5157 endif
5158
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005159" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 if haskey
5161 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005164" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5165" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005166 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 else
5168 " go down one directory
5169 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005170" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5171" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005173 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005175 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176
5177 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005178 " ----------------------------------------
5179 " NetrwBrowseChgDir: Go down one directory {{{3
5180 " ----------------------------------------
5181 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005182" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005183 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005184 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005185 endif
5186
Bram Moolenaar97d62492012-11-15 21:28:22 +01005187 " --------------------------------------
5188 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5189 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005190 if dorestore
5191 " dorestore is zero'd when a local file was hidden or bufhidden;
5192 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005194 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005195" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005197 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005200 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5202" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005203 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" 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 +02005205 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005206" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5207" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005208 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005209" 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 +02005210 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005211 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005212 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005213 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005214
Bram Moolenaar446cb832008-06-24 21:56:24 +00005215" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5216 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005217endfun
5218
5219" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005220" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5221" for thin, long, and wide: cursor placed just after banner
5222" for tree, keeps cursor on current filename
5223fun! s:NetrwBrowseUpDir(islocal)
5224" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005225 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5226 " this test needed because occasionally this function seems to be incorrectly called
5227 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005228 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005229 " directories.
5230" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5231 return
5232 endif
5233
Bram Moolenaara6878372014-03-22 21:02:50 +01005234 norm! 0
5235 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005236" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005237 let curline= getline(".")
5238 let swwline= winline() - 1
5239 if exists("w:netrw_treetop")
5240 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005241 elseif exists("b:netrw_curdir")
5242 let w:netrw_treetop= b:netrw_curdir
5243 else
5244 let w:netrw_treetop= getcwd()
5245 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005247 let curfile = getline(".")
5248 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005249 if a:islocal
5250 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5251 else
5252 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5253 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005254" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5255" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5256 if w:netrw_treetop == '/'
5257 keepj call search('^\M'.curfile,"w")
5258 elseif curfile == '../'
5259 keepj call search('^\M'.curfile,"wb")
5260 else
5261" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5262 while 1
5263 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5264 let treepath= s:NetrwTreePath(w:netrw_treetop)
5265" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5266 if treepath == curpath
5267 break
5268 endif
5269 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005270 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005271
Bram Moolenaara6878372014-03-22 21:02:50 +01005272 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005273" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005274 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005275 if exists("b:netrw_curdir")
5276 let curdir= b:netrw_curdir
5277 else
5278 let curdir= expand(getcwd())
5279 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005280 if a:islocal
5281 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5282 else
5283 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5284 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005285 call s:RestorePosn(s:netrw_posn)
5286 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005287 let curdir= '\<'. escape(curdir, '~'). '/'
5288 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005289 endif
5290" call Dret("s:NetrwBrowseUpDir")
5291endfun
5292
5293" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005294" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005295" given filename; typically this means given their extension.
5296" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005297fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005298 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005299" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005300
Bram Moolenaar91359012019-11-30 17:57:03 +01005301 if a:remote == 0 && isdirectory(a:fname)
5302 " if its really just a local directory, then do a "gf" instead
5303" 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 +01005304" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5305 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005306" call Dret("netrw#BrowseX")
5307 return
5308 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5309 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5310" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5311" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5312" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5313" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5314 norm! gf
5315" call Dret("netrw#BrowseX")
5316 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005317 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005318" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005319
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005320 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5321 let remote = a:remote
5322 else
5323 let remote = 0
5324 endif
5325
Bram Moolenaar97d62492012-11-15 21:28:22 +01005326 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005327 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005328" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005329
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005330 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5331 let awkeep = &aw
5332 set noaw
5333
Bram Moolenaar5c736222010-01-06 20:54:52 +01005334 " special core dump handler
5335 if a:fname =~ '/core\(\.\d\+\)\=$'
5336 if exists("g:Netrw_corehandler")
5337 if type(g:Netrw_corehandler) == 2
5338 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005339" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005340 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005341 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005343" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005344 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005345 if type(Fncref) == 2
5346 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005347 endif
5348 endfor
5349 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005350" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005351 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005352 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005353 let &aw= awkeep
5354" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005355 return
5356 endif
5357 endif
5358
Bram Moolenaar446cb832008-06-24 21:56:24 +00005359 " set up the filename
5360 " (lower case the extension, make a local copy of a remote file)
5361 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005362 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005363 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005364 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005365 if exten =~ "[\\/]"
5366 let exten= ""
5367 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005368" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005369
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005370 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005371 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005372" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005373 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005374 call netrw#NetRead(3,a:fname)
5375 " attempt to rename tempfile
5376 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005377 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005378" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5379" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005380 if s:netrw_tmpfile != newname && newname != ""
5381 if rename(s:netrw_tmpfile,newname) == 0
5382 " renaming succeeded
5383" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5384 let fname= newname
5385 else
5386 " renaming failed
5387" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5388 let fname= s:netrw_tmpfile
5389 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005390 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005391 let fname= s:netrw_tmpfile
5392 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005393 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005394" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005395 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005396 " special ~ handler for local
5397 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005398" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5399 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005400 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005401 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005402" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5403" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005404
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005405 " set up redirection (avoids browser messages)
5406 " by default, g:netrw_suppress_gx_mesg is true
5407 if g:netrw_suppress_gx_mesg
5408 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005409 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005410 let redir= substitute(&srr,"%s","nul","")
5411 else
5412 let redir= substitute(&srr,"%s","/dev/null","")
5413 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005414 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005415 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005417 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005419 else
5420 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005422" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005424 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005426" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005427 if g:netrw_browsex_viewer =~ '\s'
5428 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5429 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5430 let oviewer = ''
5431 let cnt = 1
5432 while !executable(viewer) && viewer != oviewer
5433 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5434 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5435 let cnt = cnt + 1
5436 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005437" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005438 endwhile
5439 else
5440 let viewer = g:netrw_browsex_viewer
5441 let viewopt = ""
5442 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005443" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005444 endif
5445
5446 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005447" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005449" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 let ret= netrwFileHandlers#Invoke(exten,fname)
5451
5452 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005453" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005454 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005455 let ret= v:shell_error
5456
Nir Lichtman1e34b952024-05-08 19:19:34 +02005457 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005458" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005459 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005460 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005461 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005462 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005463 else
5464 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5465 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005466 let ret= v:shell_error
5467
Bram Moolenaar97d62492012-11-15 21:28:22 +01005468 elseif has("win32unix")
5469 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005470" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005471 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005472" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005473 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005474 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005475" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005476 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005477 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005478" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005479 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005480 else
5481 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5482 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005483 let ret= v:shell_error
5484
Bram Moolenaar85850f32019-07-19 22:05:51 +02005485 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005486" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5487 if a:fname =~ '^https\=://'
5488 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5489 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005490" call Decho("fname<".fname.">")
5491" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005492 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5493
5494 else
5495 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5496 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005497 let ret= v:shell_error
5498
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005499 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5500" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5501 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5502 let ret= v:shell_error
5503
5504 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5505" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5506 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5507 let ret= v:shell_error
5508
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005509 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005510" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005511 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005512 let ret= v:shell_error
5513
5514 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005515" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005516 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005517 let ret= v:shell_error
5518
5519 else
5520 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005521" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005522 let ret= netrwFileHandlers#Invoke(exten,fname)
5523 endif
5524
5525 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5526 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005527" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005528 let ret= netrwFileHandlers#Invoke(exten,fname)
5529 endif
5530
Bram Moolenaarc236c162008-07-13 17:41:49 +00005531 " restoring redraw! after external file handlers
5532 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005533
5534 " cleanup: remove temporary file,
5535 " delete current buffer if success with handler,
5536 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005537 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005538 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005539" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005540"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005541" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542" endif
5543
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005544 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005545 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005547 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005549 if use_ctrlo
5550 exe "sil! NetrwKeepj norm! \<c-o>"
5551 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005552 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005553" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005554 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005555 let @@ = ykeep
5556 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005557
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005558" call Dret("netrw#BrowseX")
5559endfun
5560
5561" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005562" netrw#GX: gets word under cursor for gx support {{{2
5563" See also: netrw#BrowseXVis
5564" netrw#BrowseX
5565fun! netrw#GX()
5566" call Dfunc("netrw#GX()")
5567 if &ft == "netrw"
5568 let fname= s:NetrwGetWord()
5569 else
5570 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5571 endif
5572" call Dret("netrw#GX <".fname.">")
5573 return fname
5574endfun
5575
5576" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005577" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5578fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005579 let dict={}
5580 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005581 norm! gv"ay
5582 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005583 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005584 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005585endfun
5586
5587" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005588" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5589" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5590" to become an unlisted buffer, so in that case don't bwipe it.
5591fun! s:NetrwBufRename(newname)
5592" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5593" call Dredir("ls!","s:NetrwBufRename (before rename)")
5594 let oldbufname= bufname(bufnr("%"))
5595" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5596
5597 if oldbufname != a:newname
5598" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5599 let b:junk= 1
5600" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5601 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005602" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005603 let oldbufnr= bufnr(oldbufname)
5604" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5605" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5606 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5607" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5608 exe "bwipe! ".oldbufnr
5609" else " Decho
5610" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005611" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5612" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5613" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005614 endif
5615" call Dredir("ls!","s:NetrwBufRename (after rename)")
5616" else " Decho
5617" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5618 endif
5619
5620" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5621endfun
5622
5623" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005624" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005625fun! netrw#CheckIfRemote(...)
5626" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5627 if a:0 > 0
5628 let curfile= a:1
5629 else
5630 let curfile= expand("%")
5631 endif
5632" call Decho("curfile<".curfile.">")
5633 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005634" call Dret("netrw#CheckIfRemote 1")
5635 return 1
5636 else
5637" call Dret("netrw#CheckIfRemote 0")
5638 return 0
5639 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005640endfun
5641
5642" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005643" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5644fun! s:NetrwChgPerm(islocal,curdir)
5645" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005646 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005647 call inputsave()
5648 let newperm= input("Enter new permission: ")
5649 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005650 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5651 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5652" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005653 call system(chgperm)
5654 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005655 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005656 endif
5657 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005658 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005659 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005660 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005661" call Dret("s:NetrwChgPerm")
5662endfun
5663
5664" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005665" s:CheckIfKde: checks if kdeinit is running {{{2
5666" Returns 0: kdeinit not running
5667" 1: kdeinit is running
5668fun! s:CheckIfKde()
5669" call Dfunc("s:CheckIfKde()")
5670 " seems kde systems often have gnome-open due to dependencies, even though
5671 " gnome-open's subsidiary display tools are largely absent. Kde systems
5672 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5673 if !exists("s:haskdeinit")
5674 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005675 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005676 if v:shell_error
5677 let s:haskdeinit = 0
5678 endif
5679 else
5680 let s:haskdeinit= 0
5681 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005682" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005683 endif
5684
5685" call Dret("s:CheckIfKde ".s:haskdeinit)
5686 return s:haskdeinit
5687endfun
5688
5689" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005690" s:NetrwClearExplore: clear explore variables (if any) {{{2
5691fun! s:NetrwClearExplore()
5692" call Dfunc("s:NetrwClearExplore()")
5693 2match none
5694 if exists("s:explore_match") |unlet s:explore_match |endif
5695 if exists("s:explore_indx") |unlet s:explore_indx |endif
5696 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5697 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5698 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5699 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5700 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5701 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5702 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5703" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005704" call Dret("s:NetrwClearExplore")
5705endfun
5706
5707" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005708" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5709fun! s:NetrwEditBuf(bufnum)
5710" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5711 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5712" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5713 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5714 else
5715" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005716 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005717 endif
5718" call Dret("s:NetrwEditBuf")
5719endfun
5720
5721" ---------------------------------------------------------------------
5722" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5723" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5724fun! s:NetrwEditFile(cmd,opt,fname)
5725" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5726 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5727" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5728 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5729 else
5730" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005731 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5732 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5733 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005734 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5735 endif
5736" call Dret("s:NetrwEditFile")
5737endfun
5738
5739" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005740" s:NetrwExploreListUniq: {{{2
5741fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005742" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005743
5744 " this assumes that the list is already sorted
5745 let newexplist= []
5746 for member in a:explist
5747 if !exists("uniqmember") || member != uniqmember
5748 let uniqmember = member
5749 let newexplist = newexplist + [ member ]
5750 endif
5751 endfor
5752
Bram Moolenaar15146672011-10-20 22:22:38 +02005753" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005754 return newexplist
5755endfun
5756
5757" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005758" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5759fun! s:NetrwForceChgDir(islocal,newdir)
5760" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005761 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005762 if a:newdir !~ '/$'
5763 " ok, looks like force is needed to get directory-style treatment
5764 if a:newdir =~ '@$'
5765 let newdir= substitute(a:newdir,'@$','/','')
5766 elseif a:newdir =~ '[*=|\\]$'
5767 let newdir= substitute(a:newdir,'.$','/','')
5768 else
5769 let newdir= a:newdir.'/'
5770 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005771" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005772 else
5773 " should already be getting treatment as a directory
5774 let newdir= a:newdir
5775 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005776 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005777 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005778 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005779" call Dret("s:NetrwForceChgDir")
5780endfun
5781
5782" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005783" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005784" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5785" expr : this is the expression to follow the directory. Will use s:ComposePath()
5786" pare =1: remove the current directory from the resulting glob() filelist
5787" =0: leave the current directory in the resulting glob() filelist
5788fun! s:NetrwGlob(direntry,expr,pare)
5789" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005790 if netrw#CheckIfRemote()
5791 keepalt 1sp
5792 keepalt enew
5793 let keep_liststyle = w:netrw_liststyle
5794 let w:netrw_liststyle = s:THINLIST
5795 if s:NetrwRemoteListing() == 0
5796 keepj keepalt %s@/@@
5797 let filelist= getline(1,$)
5798 q!
5799 else
5800 " remote listing error -- leave treedict unchanged
5801 let filelist= w:netrw_treedict[a:direntry]
5802 endif
5803 let w:netrw_liststyle= keep_liststyle
5804 else
Christian Brabandt14879472024-06-13 21:25:35 +02005805 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005806 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005807 " escape [ so it is not detected as wildcard character, see :h wildcard
5808 let path= substitute(path, '[', '[[]', 'g')
5809 endif
5810 if v:version > 704 || (v:version == 704 && has("patch656"))
5811 let filelist= glob(path,0,1,1)
5812 else
5813 let filelist= glob(path,0,1)
5814 endif
5815 if a:pare
5816 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5817 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005818 endif
5819" call Dret("s:NetrwGlob ".string(filelist))
5820 return filelist
5821endfun
5822
5823" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005824" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5825fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005826" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005827 if a:newfile =~ '[/@*=|\\]$'
5828 let newfile= substitute(a:newfile,'.$','','')
5829 else
5830 let newfile= a:newfile
5831 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005832 if a:islocal
5833 call s:NetrwBrowseChgDir(a:islocal,newfile)
5834 else
5835 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5836 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005837" call Dret("s:NetrwForceFile")
5838endfun
5839
5840" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005841" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5842" and switches the hiding mode. The actual hiding is done by
5843" s:NetrwListHide().
5844" g:netrw_hide= 0: show all
5845" 1: show not-hidden files
5846" 2: show hidden files only
5847fun! s:NetrwHide(islocal)
5848" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005849 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005850 let svpos= winsaveview()
5851" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005852
5853 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005854" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5855" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005856
5857 " hide the files in the markfile list
5858 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005859" 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 +00005860 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5861 " remove fname from hiding list
5862 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5863 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5864 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005865" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866 else
5867 " append fname to hiding list
5868 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5869 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5870 else
5871 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5872 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005873" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874 endif
5875 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005876 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877 let g:netrw_hide= 1
5878
5879 else
5880
5881 " switch between show-all/show-not-hidden/show-hidden
5882 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005884 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005885 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005886 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887" call Dret("NetrwHide")
5888 return
5889 endif
5890 endif
5891
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005892 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005893" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5894 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005895 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005896" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005897endfun
5898
5899" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005900" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5901fun! s:NetrwHideEdit(islocal)
5902" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5903
5904 let ykeep= @@
5905 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005906 let svpos= winsaveview()
5907" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005908
5909 " get new hiding list from user
5910 call inputsave()
5911 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5912 call inputrestore()
5913 let g:netrw_list_hide= newhide
5914" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5915
5916 " refresh the listing
5917 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5918
5919 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005920" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5921 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005922 let @@= ykeep
5923
5924" call Dret("NetrwHideEdit")
5925endfun
5926
5927" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928" s:NetrwHidden: invoked by "gh" {{{2
5929fun! s:NetrwHidden(islocal)
5930" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005931 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005932 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005933 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005934" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005935
5936 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005937 " remove .file pattern from hiding list
5938" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005939 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005940 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005941" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005942 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5943 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005944" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5946 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005947 if g:netrw_list_hide =~ '^,'
5948 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005950
5951 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005952 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005953" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5954 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005955 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956" call Dret("s:NetrwHidden")
5957endfun
5958
5959" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005960" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5961fun! s:NetrwHome()
5962 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005963 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005964 else
5965 " go to vim plugin home
5966 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005967 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005969 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005970 let home= basehome."/.vim"
5971 break
5972 endif
5973 endfor
5974 if home == ""
5975 " just pick the first directory
5976 let home= substitute(&rtp,',.*$','','')
5977 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005978 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005979 let home= substitute(home,'/','\\','g')
5980 endif
5981 endif
5982 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005983 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005985 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005986" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005987 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005989" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005990 call mkdir(home)
5991 endif
5992 endif
5993 let g:netrw_home= home
5994 return home
5995endfun
5996
5997" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005998" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5999fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006000 if exists("s:netrwdrag")
6001 return
6002 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006003 if &ft != "netrw"
6004 return
6005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006006" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006007
Bram Moolenaar97d62492012-11-15 21:28:22 +01006008 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006009 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006010 while getchar(0) != 0
6011 "clear the input stream
6012 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006013 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006014 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006015 let mouse_lnum = v:mouse_lnum
6016 let wlastline = line('w$')
6017 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006018" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6019" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006020 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6021 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006022 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006023" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6024 return
6025 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006026 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006027 " 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 +01006028 " without this test when its disabled.
6029 " 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 +01006030" 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 +01006031 if v:mouse_col > virtcol('.')
6032 let @@= ykeep
6033" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6034 return
6035 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006036
Bram Moolenaar446cb832008-06-24 21:56:24 +00006037 if a:islocal
6038 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006039 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006040 endif
6041 else
6042 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006043 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006044 endif
6045 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006046 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006047" call Dret("s:NetrwLeftmouse")
6048endfun
6049
6050" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6052fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006053 if &ft != "netrw"
6054 return
6055 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006056" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6057 call s:NetrwMarkFileTgt(a:islocal)
6058" call Dret("s:NetrwCLeftmouse")
6059endfun
6060
6061" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006062" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6063" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006064" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006065" a:islocal=2 : <c-r> used, remote
6066" a:islocal=3 : <c-r> used, local
6067fun! s:NetrwServerEdit(islocal,fname)
6068" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6069 let islocal = a:islocal%2 " =0: remote =1: local
6070 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006073 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006075 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006078 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006079 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6080 unlet s:netrw_browse_split_{winnr()}
6081 endif
6082 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6083" call Dret("s:NetrwServerEdit")
6084 return
6085 endif
6086
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006089" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006090
6091 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006092" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093 let srvrname = g:netrw_browse_split[0]
6094 let tabnum = g:netrw_browse_split[1]
6095 let winnum = g:netrw_browse_split[2]
6096
6097 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099
6100 if !ctrlr
6101 " user must have closed the server window and the user did not use <c-r>, but
6102 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006105 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006106 endif
6107 let g:netrw_browse_split= 0
6108 if exists("s:netrw_browse_split_".winnr())
6109 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6110 endif
6111 call s:NetrwBrowseChgDir(islocal,a:fname)
6112" call Dret("s:NetrwServerEdit")
6113 return
6114
6115 elseif has("win32") && executable("start")
6116 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118 call system("start gvim --servername ".srvrname)
6119
6120 else
6121 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006122" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006123 call system("gvim --servername ".srvrname)
6124 endif
6125 endif
6126
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006127" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006128 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6129 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131
6132 else
6133
6134 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6135
6136 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006137" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006138 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006139 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006140 endif
6141 let g:netrw_browse_split= 0
6142 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6143" call Dret("s:NetrwServerEdit")
6144 return
6145
6146 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006147" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006148 if has("win32") && executable("start")
6149 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006150" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 call system("start gvim --servername ".g:netrw_servername)
6152 else
6153 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006154" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006155 call system("gvim --servername ".g:netrw_servername)
6156 endif
6157 endif
6158 endif
6159
6160 while 1
6161 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006162" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6163 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006164 break
6165 catch /^Vim\%((\a\+)\)\=:E241/
6166 sleep 200m
6167 endtry
6168 endwhile
6169
6170 if exists("g:netrw_browse_split")
6171 if type(g:netrw_browse_split) != 3
6172 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6173 endif
6174 unlet g:netrw_browse_split
6175 endif
6176 let g:netrw_browse_split= [g:netrw_servername,1,1]
6177 endif
6178
6179 else
6180 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6181 endif
6182
6183" call Dret("s:NetrwServerEdit")
6184endfun
6185
6186" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006187" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6188fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006189 if &ft != "netrw"
6190 return
6191 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006192" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006193
Bram Moolenaar8d043172014-01-23 14:24:41 +01006194 let s:ngw= s:NetrwGetWord()
6195 call s:NetrwMarkFile(a:islocal,s:ngw)
6196
6197" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006198endfun
6199
6200" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006201" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6202" Used to mark multiple files.
6203fun! s:NetrwSLeftdrag(islocal)
6204" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6205 if !exists("s:netrwdrag")
6206 let s:netrwdrag = winnr()
6207 if a:islocal
6208 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006209 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006210 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006211 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006212 endif
6213 let ngw = s:NetrwGetWord()
6214 if !exists("s:ngw") || s:ngw != ngw
6215 call s:NetrwMarkFile(a:islocal,ngw)
6216 endif
6217 let s:ngw= ngw
6218" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6219endfun
6220
6221" ---------------------------------------------------------------------
6222" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6223fun! s:NetrwSLeftrelease(islocal)
6224" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6225 if exists("s:netrwdrag")
6226 nunmap <s-leftrelease>
6227 let ngw = s:NetrwGetWord()
6228 if !exists("s:ngw") || s:ngw != ngw
6229 call s:NetrwMarkFile(a:islocal,ngw)
6230 endif
6231 if exists("s:ngw")
6232 unlet s:ngw
6233 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006234 unlet s:netrwdrag
6235 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006236" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006237endfun
6238
6239" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006240" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6241" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006242fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006243" 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 +02006244" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006245 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006246
6247 " 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 +02006248 " How-it-works: take the hiding command, convert it into a range.
6249 " Duplicate characters don't matter.
6250 " Remove all such characters from the '/~@#...890' string.
6251 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006252" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006253 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006254 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006255" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256
6257 while listhide != ""
6258 if listhide =~ ','
6259 let hide = substitute(listhide,',.*$','','e')
6260 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6261 else
6262 let hide = listhide
6263 let listhide = ""
6264 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006265" 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 +01006266 if g:netrw_sort_by =~ '^[ts]'
6267 if hide =~ '^\^'
6268" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6269 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6270 elseif hide =~ '^\\(\^'
6271 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6272 endif
6273" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6274 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006275
6276 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006277" 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 +00006278 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006279" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006280 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006282" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006283 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006287
Bram Moolenaar446cb832008-06-24 21:56:24 +00006288 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006291 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006292" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006293 endif
6294
Bram Moolenaaradc21822011-04-01 18:03:16 +02006295 " remove any blank lines that have somehow remained.
6296 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006297 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006298
Bram Moolenaar97d62492012-11-15 21:28:22 +01006299 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006300" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301endfun
6302
6303" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006305" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006307" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308
Bram Moolenaar97d62492012-11-15 21:28:22 +01006309 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006310 " get name of new directory from user. A bare <CR> will skip.
6311 " if its currently a directory, also request will be skipped, but with
6312 " a message.
6313 call inputsave()
6314 let newdirname= input("Please give directory name: ")
6315 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006316" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317
6318 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006319 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006320" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321 return
6322 endif
6323
6324 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006325" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006326
6327 " Local mkdir:
6328 " sanity checks
6329 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006330" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6331 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006333 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006335 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006336" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 return
6338 endif
6339 if s:FileReadable(fullnewdir)
6340 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006341 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006343 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006344" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345 return
6346 endif
6347
6348 " requested new local directory is neither a pre-existing file or
6349 " directory, so make it!
6350 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006351 if has("unix")
6352 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6353 else
6354 call mkdir(fullnewdir,"p")
6355 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006356 else
6357 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006358 if s:NetrwLcd(b:netrw_curdir)
6359" call Dret("s:NetrwMakeDir : lcd failure")
6360 return
6361 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006362" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006363 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006364 if v:shell_error != 0
6365 let @@= ykeep
6366 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 +01006367" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006368 return
6369 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006371" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006372 if s:NetrwLcd(netrw_origdir)
6373" call Dret("s:NetrwBrowse : lcd failure")
6374 return
6375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006376 endif
6377 endif
6378
6379 if v:shell_error == 0
6380 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006381" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006382 let svpos= winsaveview()
6383" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006385" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6386 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006387 elseif !exists("g:netrw_quiet")
6388 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6389 endif
6390" redraw!
6391
6392 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006393 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006394" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006395 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6396 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006397 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 if v:shell_error == 0
6399 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006400 let svpos= winsaveview()
6401" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006402 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006403" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6404 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006406 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 endif
6408" redraw!
6409
6410 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006411 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006412 let svpos= winsaveview()
6413" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006414" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006415 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006416" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006417 let remotepath= b:netrw_fname
6418 else
6419 let remotepath= ""
6420 endif
6421 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006422 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6424 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006425
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006427 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006428 let svpos= winsaveview()
6429" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006432" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006433 let remotepath= b:netrw_fname
6434 else
6435 let remotepath= ""
6436 endif
6437 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006438 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006439" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6440 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006441 endif
6442
Bram Moolenaar97d62492012-11-15 21:28:22 +01006443 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006444" call Dret("s:NetrwMakeDir")
6445endfun
6446
6447" ---------------------------------------------------------------------
6448" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6449fun! s:TreeSqueezeDir(islocal)
6450" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6451 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6452 " its a tree-listing style
6453 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006454 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006455 let depth = strchars(substitute(curdepth,' ','','g'))
6456 let srch = -1
6457" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6458" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006459" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006460" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6461 if depth >= 2
6462 NetrwKeepj norm! 0
6463 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6464 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6465" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6466" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6467 elseif depth == 1
6468 NetrwKeepj norm! 0
6469 let treedepthchr= substitute(s:treedepthstring,' ','','')
6470 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6471" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6472 endif
6473 if srch > 0
6474" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6475 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6476 exe srch
6477 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006478 endif
6479" call Dret("s:TreeSqueezeDir")
6480endfun
6481
6482" ---------------------------------------------------------------------
6483" s:NetrwMaps: {{{2
6484fun! s:NetrwMaps(islocal)
6485" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6486
Bram Moolenaar85850f32019-07-19 22:05:51 +02006487 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006489" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006490 if !hasmapto("<Plug>NetrwReturn")
6491 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006492" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006493 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6494 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006495" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6497 endif
6498 endif
6499 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006500" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006501 endif
6502
Bram Moolenaar85850f32019-07-19 22:05:51 +02006503 " generate default <Plug> maps {{{3
6504 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006505 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006506 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6507 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6508 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6509 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6510 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6511 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6512 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6513 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6514 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6515 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6516" ---------------------------------------------------------------------
6517" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6518" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6519" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6520" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6521" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6522" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6523" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6524" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6525" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6526" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6527" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6528" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6529" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6530" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6531" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6532" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6533" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6534" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6535" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6536" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6537" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6538" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6539" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6540" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6541" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6542" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6543" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6544" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6545" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6546" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6547" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6548" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6549" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6550" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6551" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6552" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6553" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6554" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6555" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6556" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6557" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6558" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6559" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6560" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6561" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6562" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6563" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6564
Bram Moolenaara6878372014-03-22 21:02:50 +01006565 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006566" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006567 " local normal-mode maps {{{3
6568 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6577 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6578 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6579" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006580 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6581 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6582 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006583 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006584 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006585 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6586 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6588 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006589 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6590 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6591 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6595 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6596 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006603 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006604 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6605 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6607 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6612 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006613 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6614 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6615 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006617 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006618 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6619 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006621 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6623 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6624 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006625 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6626 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006627
6628 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 +01006629 if !hasmapto('<Plug>NetrwHideEdit')
6630 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 if !hasmapto('<Plug>NetrwRefresh')
6634 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006635 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006636 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 +01006637 if s:didstarstar || !mapcheck("<s-down>","n")
6638 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006639 endif
6640 if s:didstarstar || !mapcheck("<s-up>","n")
6641 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 if !hasmapto('<Plug>NetrwTreeSqueeze')
6644 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006645 endif
6646 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006647 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6648 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006649 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6650 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6651 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6652 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6653 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6654 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6655 imap <buffer> <leftmouse> <Plug>ILeftmouse
6656 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006657 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6658 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6659 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6660 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6661 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006662 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006663 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6664 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006666 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6667 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6668 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6669 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6670 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6671 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6672 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006673 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6674
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675 " support user-specified maps
6676 call netrw#UserMaps(1)
6677
Bram Moolenaar85850f32019-07-19 22:05:51 +02006678 else
6679 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006680" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006681 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006682 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6691 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6692 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6693" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006694 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6695 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6696 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6697 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6698 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6699 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6701 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006703 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006704 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6708 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6709 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006716 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006717 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6720 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6721 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006722 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6723 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6724 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6725 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006726 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006727 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6728 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006729 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006730 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 +01006731 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6734 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6735 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6736 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6737 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6738 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6739 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 if !hasmapto('<Plug>NetrwHideEdit')
6741 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006742 endif
6743 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6744 if !hasmapto('<Plug>NetrwRefresh')
6745 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006746 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006747 if !hasmapto('<Plug>NetrwTreeSqueeze')
6748 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006749 endif
6750 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006751
6752 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006753 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006754
6755 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6756 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006758 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006760 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006762 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006764 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006766 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006767 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6768 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6769 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006772 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6773 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6777 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6778 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6780 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6781 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006782 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006783
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784 " support user-specified maps
6785 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006786 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006787
6788" call Dret("s:NetrwMaps")
6789endfun
6790
6791" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006792" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006793" If -buffer, the command is only available from within netrw buffers
6794" Otherwise, the command is available from any window, so long as netrw
6795" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006796fun! s:NetrwCommands(islocal)
6797" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6798
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006799 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6800 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006801 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 +01006802 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006803 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006804 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006805 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006806 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006807 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006808
6809" call Dret("s:NetrwCommands")
6810endfun
6811
6812" ---------------------------------------------------------------------
6813" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6814" glob()ing only works with local files
6815fun! s:NetrwMarkFiles(islocal,...)
6816" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006817 let curdir = s:NetrwGetCurdir(a:islocal)
6818 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006819 while i <= a:0
6820 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006821 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006822 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006823 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006824 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006825 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006826 else
6827 let mffiles= [a:{i}]
6828 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006830 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006832 call s:NetrwMarkFile(a:islocal,mffile)
6833 endfor
6834 let i= i + 1
6835 endwhile
6836" call Dret("s:NetrwMarkFiles")
6837endfun
6838
6839" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006841fun! s:NetrwMarkTarget(...)
6842" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6843 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006844 let curdir = s:NetrwGetCurdir(1)
6845 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006846 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006847 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6848 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006851 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6853 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006854 let svpos = winsaveview()
6855" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006856 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006857" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6858 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006859" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006860endfun
6861
6862" ---------------------------------------------------------------------
6863" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6864" mark and unmark files. If a markfile list exists,
6865" then the rename and delete functions will use it instead
6866" of whatever may happen to be under the cursor at that
6867" moment. When the mouse and gui are available,
6868" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006869"
6870" Creates two lists
6871" s:netrwmarkfilelist -- holds complete paths to all marked files
6872" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6873"
6874" Creates a marked file match string
6875" s:netrwmarfilemtch_# -- used with 2match to display marked files
6876"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006877" Creates a buffer version of islocal
6878" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006879fun! s:NetrwMarkFile(islocal,fname)
6880" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006881" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006882
6883 " sanity check
6884 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006885" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006886 return
6887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006888 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006889
Bram Moolenaar97d62492012-11-15 21:28:22 +01006890 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006891 let curbufnr= bufnr("%")
yasuda38cfa2b2024-08-22 20:54:47 +02006892 let leader= '\(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006893 if a:fname =~ '\a$'
6894 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6895 else
6896 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6897 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006898
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006899 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006900 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6902" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6903" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006904 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006905
6906 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006907 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006908" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006910 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911
6912 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006913 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006914" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006915 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6916 if s:netrwmarkfilelist_{curbufnr} == []
6917 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006918" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006919 call s:NetrwUnmarkList(curbufnr,curdir)
6920 else
6921 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006922" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006924 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 for fname in s:netrwmarkfilelist_{curbufnr}
6926 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006927 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006928 else
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 endif
6931 let first= 0
6932 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934 endif
6935 endif
6936
6937 else
6938 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006939" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6944" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006945
6946 " build initial markfile matching pattern
6947 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006948 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006949 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006950 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006952" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 endif
6954
6955 " handle global markfilelist
6956 if exists("s:netrwmarkfilelist")
6957 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6958 if index(s:netrwmarkfilelist,dname) == -1
6959 " append new filename to global markfilelist
6960 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006961" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006962 else
6963 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006964" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6965" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006966 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006967" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006969" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 unlet s:netrwmarkfilelist
6971 endif
6972 endif
6973 else
6974 " initialize new global-directory markfilelist
6975 let s:netrwmarkfilelist= []
6976 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006977" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 endif
6979
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006980 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006981 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6982 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6983" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6984 if exists("g:did_drchip_netrwlist_syntax")
6985 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6986 endif
6987 else
6988" " call Decho("2match none",'~'.expand("<slnum>"))
6989 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006991 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006992 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006993" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6994" 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 +00006995endfun
6996
6997" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006998" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6999" mA: move the argument list to marked file list (tomflist=1)
7000" Uses the global marked file list
7001fun! s:NetrwMarkFileArgList(islocal,tomflist)
7002" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7003
7004 let svpos = winsaveview()
7005" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7006 let curdir = s:NetrwGetCurdir(a:islocal)
7007 let curbufnr = bufnr("%")
7008
7009 if a:tomflist
7010 " mA: move argument list to marked file list
7011 while argc()
7012 let fname= argv(0)
7013" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7014 exe "argdel ".fnameescape(fname)
7015 call s:NetrwMarkFile(a:islocal,fname)
7016 endwhile
7017
7018 else
7019 " ma: move marked file list to argument list
7020 if exists("s:netrwmarkfilelist")
7021
7022 " for every filename in the marked list
7023 for fname in s:netrwmarkfilelist
7024" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7025 exe "argadd ".fnameescape(fname)
7026 endfor " for every file in the marked list
7027
7028 " unmark list and refresh
7029 call s:NetrwUnmarkList(curbufnr,curdir)
7030 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7031" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7032 NetrwKeepj call winrestview(svpos)
7033 endif
7034 endif
7035
7036" call Dret("s:NetrwMarkFileArgList")
7037endfun
7038
7039" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007040" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7041" compress/decompress files using the programs
7042" in g:netrw_compress and g:netrw_uncompress,
7043" using g:netrw_compress_suffix to know which to
7044" do. By default:
7045" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007046" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007047fun! s:NetrwMarkFileCompress(islocal)
7048" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007049 let svpos = winsaveview()
7050" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007051 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007052 let curbufnr = bufnr("%")
7053
Bram Moolenaarff034192013-04-24 18:51:19 +02007054 " sanity check
7055 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007056 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007057" call Dret("s:NetrwMarkFileCompress")
7058 return
7059 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007060" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007061
Bram Moolenaar446cb832008-06-24 21:56:24 +00007062 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007063
7064 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007066 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007067" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 if exists("g:netrw_decompress['".sfx."']")
7069 " fname has a suffix indicating that its compressed; apply associated decompression routine
7070 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007071" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007072 let exe= netrw#WinPath(exe)
7073 if a:islocal
7074 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007075 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007076 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007077 call system(exe." ".fname)
7078 if v:shell_error
7079 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007080 endif
7081 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007082 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7083 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007084 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007085
Bram Moolenaarff034192013-04-24 18:51:19 +02007086 endif
7087 unlet sfx
7088
Bram Moolenaar446cb832008-06-24 21:56:24 +00007089 if exists("exe")
7090 unlet exe
7091 elseif a:islocal
7092 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007093 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007094 if v:shell_error
7095 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7096 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097 else
7098 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007099 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007100 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007101 endfor " for every file in the marked list
7102
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007104 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007105" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7106 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107 endif
7108" call Dret("s:NetrwMarkFileCompress")
7109endfun
7110
7111" ---------------------------------------------------------------------
7112" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7113" If no marked files, then set up directory as the
7114" target. Currently does not support copying entire
7115" directories. Uses the local-buffer marked file list.
7116" Returns 1=success (used by NetrwMarkFileMove())
7117" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007118fun! s:NetrwMarkFileCopy(islocal,...)
7119" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7120
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007121 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007122 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007123 if b:netrw_curdir !~ '/$'
7124 if !exists("b:netrw_curdir")
7125 let b:netrw_curdir= curdir
7126 endif
7127 let b:netrw_curdir= b:netrw_curdir."/"
7128 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007129
Bram Moolenaarff034192013-04-24 18:51:19 +02007130 " sanity check
7131 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007132 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007133" call Dret("s:NetrwMarkFileCopy")
7134 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007136" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007137
Bram Moolenaar446cb832008-06-24 21:56:24 +00007138 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007139 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007140" call Dret("s:NetrwMarkFileCopy 0")
7141 return 0
7142 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007143" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007144
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007145 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007146 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007147" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007148 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007149 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7150" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7151 return
7152 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007153
7154 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007155 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007156 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7157 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007158" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007159 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007160 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7161 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007162" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007163 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007164 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165 let oldname = a:1
7166 else
7167 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007168" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007169 let s:recursive= 1
7170 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7171 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7172 if ret == 0
7173 break
7174 endif
7175 endfor
7176 unlet s:recursive
7177 call s:NetrwUnmarkList(curbufnr,curdir)
7178" call Dret("s:NetrwMarkFileCopy ".ret)
7179 return ret
7180 endif
7181
7182 call inputsave()
7183 let newname= input("Copy ".oldname." to : ",oldname,"file")
7184 call inputrestore()
7185 if newname == ""
7186" call Dret("s:NetrwMarkFileCopy 0")
7187 return 0
7188 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007189 let args= s:ShellEscape(oldname)
7190 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007191 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007192 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7193 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007194 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007195 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007196 let args= substitute(args,'/','\\','g')
7197 let tgt = substitute(tgt, '/','\\','g')
7198 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007199 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7200 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7201 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7202 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7203" call Decho("args <".args.">",'~'.expand("<slnum>"))
7204" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205 if isdirectory(s:NetrwFile(args))
7206" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007207 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007208" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007209 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007210 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7211 " contents to a target. One must append the source directory name to the target to get xcopy to
7212 " do the right thing.
7213 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007214" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007215 endif
7216 else
7217 let copycmd= g:netrw_localcopycmd
7218 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007219 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007220 let copycmd = substitute(copycmd,'\s.*$','','')
7221 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007222 let copycmd = netrw#WinPath(copycmd).copycmdargs
7223 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007224 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007225 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007226" call Decho("args <".args.">",'~'.expand("<slnum>"))
7227" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7228" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7229" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007230 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007231 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007232 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007233 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 +01007234 else
7235 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7236 endif
7237" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007238 return 0
7239 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007240
7241 elseif a:islocal && !s:netrwmftgt_islocal
7242 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007243" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007244 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007245
7246 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007247 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007248" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007249 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007250
7251 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007252 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007253" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007254 let curdir = getcwd()
7255 let tmpdir = s:GetTempfile("")
7256 if tmpdir !~ '/'
7257 let tmpdir= curdir."/".tmpdir
7258 endif
7259 if exists("*mkdir")
7260 call mkdir(tmpdir)
7261 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007262 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007263 if v:shell_error != 0
7264 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 +01007265" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007266 return
7267 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007269 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007270 if s:NetrwLcd(tmpdir)
7271" call Dret("s:NetrwMarkFileCopy : lcd failure")
7272 return
7273 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007274 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007275 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007277 if getcwd() == tmpdir
7278 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007279 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007281 if s:NetrwLcd(curdir)
7282" call Dret("s:NetrwMarkFileCopy : lcd failure")
7283 return
7284 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007285 if delete(tmpdir,"d")
7286 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007287 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007288 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007289 if s:NetrwLcd(curdir)
7290" call Dret("s:NetrwMarkFileCopy : lcd failure")
7291 return
7292 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007293 endif
7294 endif
7295 endif
7296
7297 " -------
7298 " cleanup
7299 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007300" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007301 " remove markings from local buffer
7302 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007303" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7304" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7305" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7306" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7307" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7308" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7309 if exists("s:recursive")
7310" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7311 else
7312" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007313 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007314 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007315 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007316 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007317 else
7318 " refresh local and targets for fast browsing
7319 if !exists("s:recursive")
7320 " remove markings from local buffer
7321" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7322 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7323 endif
7324
7325 " refresh buffers
7326 if s:netrwmftgt_islocal
7327" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7328 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7329 endif
7330 if a:islocal && s:netrwmftgt != curdir
7331" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7332 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7333 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007334 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007335
Bram Moolenaar446cb832008-06-24 21:56:24 +00007336" call Dret("s:NetrwMarkFileCopy 1")
7337 return 1
7338endfun
7339
7340" ---------------------------------------------------------------------
7341" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7342" invoke vim's diff mode on the marked files.
7343" Either two or three files can be so handled.
7344" Uses the global marked file list.
7345fun! s:NetrwMarkFileDiff(islocal)
7346" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7347 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007348
Bram Moolenaarff034192013-04-24 18:51:19 +02007349 " sanity check
7350 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007351 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007352" call Dret("s:NetrwMarkFileDiff")
7353 return
7354 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355 let curdir= s:NetrwGetCurdir(a:islocal)
7356" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007357
Bram Moolenaara6878372014-03-22 21:02:50 +01007358 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007359 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360 for fname in s:netrwmarkfilelist
7361 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007363" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007364 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365 diffthis
7366 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007367 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007368" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007369 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007370 diffthis
7371 else
7372 break
7373 endif
7374 endfor
7375 call s:NetrwUnmarkList(curbufnr,curdir)
7376 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007377
Bram Moolenaar446cb832008-06-24 21:56:24 +00007378" call Dret("s:NetrwMarkFileDiff")
7379endfun
7380
7381" ---------------------------------------------------------------------
7382" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7383" Uses global markfilelist
7384fun! s:NetrwMarkFileEdit(islocal)
7385" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7386
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007387 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007388 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007389
7390 " sanity check
7391 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007392 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007393" call Dret("s:NetrwMarkFileEdit")
7394 return
7395 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007396" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007397
Bram Moolenaar446cb832008-06-24 21:56:24 +00007398 if exists("s:netrwmarkfilelist_{curbufnr}")
7399 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007400 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007401 " unmark markedfile list
7402" call s:NetrwUnmarkList(curbufnr,curdir)
7403 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007404" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007405 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007406 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007407 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007408
Bram Moolenaar446cb832008-06-24 21:56:24 +00007409" call Dret("s:NetrwMarkFileEdit")
7410endfun
7411
7412" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007413" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007414fun! s:NetrwMarkFileQFEL(islocal,qfel)
7415" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7416 call s:NetrwUnmarkAll()
7417 let curbufnr= bufnr("%")
7418
7419 if !empty(a:qfel)
7420 for entry in a:qfel
7421 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007423 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007425 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7426 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7427 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7428 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007429" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007430 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7431 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007432" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007433 endif
7434 endfor
7435 echo "(use me to edit marked files)"
7436 else
7437 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7438 endif
7439
7440" call Dret("s:NetrwMarkFileQFEL")
7441endfun
7442
7443" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007444" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7445" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7446" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7447fun! s:NetrwMarkFileExe(islocal,enbloc)
7448" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007449 let svpos = winsaveview()
7450" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007452 let curbufnr = bufnr("%")
7453
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007454 if a:enbloc == 0
7455 " individually apply command to files, one at a time
7456 " sanity check
7457 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7458 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7459" call Dret("s:NetrwMarkFileExe")
7460 return
7461 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007462" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007463
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007464 if exists("s:netrwmarkfilelist_{curbufnr}")
7465 " get the command
7466 call inputsave()
7467 let cmd= input("Enter command: ","","file")
7468 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007469" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007470 if cmd == ""
7471" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7472 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007473 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007474
7475 " apply command to marked files, individually. Substitute: filename -> %
7476 " If no %, then append a space and the filename to the command
7477 for fname in s:netrwmarkfilelist_{curbufnr}
7478 if a:islocal
7479 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007480 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481 endif
7482 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007483 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007484 endif
7485 if cmd =~ '%'
7486 let xcmd= substitute(cmd,'%',fname,'g')
7487 else
7488 let xcmd= cmd.' '.fname
7489 endif
7490 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007491" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007492 let ret= system(xcmd)
7493 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007494" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 let ret= s:RemoteSystem(xcmd)
7496 endif
7497 if v:shell_error < 0
7498 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7499 break
7500 else
yasudac75dad02024-08-22 21:06:32 +02007501 if ret !=# ''
7502 echo "\n"
7503 " skip trailing new line
7504 echo ret[0:-2]
7505 else
7506 echo ret
7507 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 endif
7509 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007510
7511 " unmark marked file list
7512 call s:NetrwUnmarkList(curbufnr,curdir)
7513
7514 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007516" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7517 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007518 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007519 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007520 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521
7522 else " apply command to global list of files, en bloc
7523
7524 call inputsave()
7525 let cmd= input("Enter command: ","","file")
7526 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007527" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007528 if cmd == ""
7529" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7530 return
7531 endif
7532 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007533 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007534 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007535 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007536 endif
7537 if a:islocal
7538 call system(cmd)
7539 if v:shell_error < 0
7540 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7541 endif
7542 else
7543 let ret= s:RemoteSystem(cmd)
7544 endif
7545 call s:NetrwUnmarkAll()
7546
7547 " refresh the listing
7548 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007549" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7550 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007551
7552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007553
Bram Moolenaar446cb832008-06-24 21:56:24 +00007554" call Dret("s:NetrwMarkFileExe")
7555endfun
7556
7557" ---------------------------------------------------------------------
7558" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7559" as the marked file(s) (toggles suffix presence)
7560" Uses the local marked file list.
7561fun! s:NetrwMarkHideSfx(islocal)
7562" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007563 let svpos = winsaveview()
7564" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007565 let curbufnr = bufnr("%")
7566
7567 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7568 if exists("s:netrwmarkfilelist_{curbufnr}")
7569
7570 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007571" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572 " construct suffix pattern
7573 if fname =~ '\.'
7574 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7575 else
7576 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7577 endif
7578 " determine if its in the hiding list or not
7579 let inhidelist= 0
7580 if g:netrw_list_hide != ""
7581 let itemnum = 0
7582 let hidelist= split(g:netrw_list_hide,',')
7583 for hidepat in hidelist
7584 if sfxpat == hidepat
7585 let inhidelist= 1
7586 break
7587 endif
7588 let itemnum= itemnum + 1
7589 endfor
7590 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007591" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007592 if inhidelist
7593 " remove sfxpat from list
7594 call remove(hidelist,itemnum)
7595 let g:netrw_list_hide= join(hidelist,",")
7596 elseif g:netrw_list_hide != ""
7597 " append sfxpat to non-empty list
7598 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7599 else
7600 " set hiding list to sfxpat
7601 let g:netrw_list_hide= sfxpat
7602 endif
7603 endfor
7604
7605 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007606 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007607" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7608 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007609 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007610 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007611 endif
7612
7613" call Dret("s:NetrwMarkHideSfx")
7614endfun
7615
7616" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007617" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007618" Uses the local marked-file list.
7619fun! s:NetrwMarkFileVimCmd(islocal)
7620" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007621 let svpos = winsaveview()
7622" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007623 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007624 let curbufnr = bufnr("%")
7625
Bram Moolenaarff034192013-04-24 18:51:19 +02007626 " sanity check
7627 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007628 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007629" call Dret("s:NetrwMarkFileVimCmd")
7630 return
7631 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007633
Bram Moolenaar15146672011-10-20 22:22:38 +02007634 if exists("s:netrwmarkfilelist_{curbufnr}")
7635 " get the command
7636 call inputsave()
7637 let cmd= input("Enter vim command: ","","file")
7638 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007640 if cmd == ""
7641" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7642 return
7643 endif
7644
7645 " apply command to marked files. Substitute: filename -> %
7646 " If no %, then append a space and the filename to the command
7647 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 if a:islocal
7650 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007651 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007653 exe cmd
7654 exe "sil! keepalt wq!"
7655 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007656" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007657 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007658 endif
7659 endfor
7660
7661 " unmark marked file list
7662 call s:NetrwUnmarkList(curbufnr,curdir)
7663
7664 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007665 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007666" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7667 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007668 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007669 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007671
Bram Moolenaar15146672011-10-20 22:22:38 +02007672" call Dret("s:NetrwMarkFileVimCmd")
7673endfun
7674
7675" ---------------------------------------------------------------------
7676" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7677" as the marked file(s) (toggles suffix presence)
7678" Uses the local marked file list.
7679fun! s:NetrwMarkHideSfx(islocal)
7680" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007681 let svpos = winsaveview()
7682" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007683 let curbufnr = bufnr("%")
7684
7685 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7686 if exists("s:netrwmarkfilelist_{curbufnr}")
7687
7688 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007689" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007690 " construct suffix pattern
7691 if fname =~ '\.'
7692 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7693 else
7694 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7695 endif
7696 " determine if its in the hiding list or not
7697 let inhidelist= 0
7698 if g:netrw_list_hide != ""
7699 let itemnum = 0
7700 let hidelist= split(g:netrw_list_hide,',')
7701 for hidepat in hidelist
7702 if sfxpat == hidepat
7703 let inhidelist= 1
7704 break
7705 endif
7706 let itemnum= itemnum + 1
7707 endfor
7708 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007709" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007710 if inhidelist
7711 " remove sfxpat from list
7712 call remove(hidelist,itemnum)
7713 let g:netrw_list_hide= join(hidelist,",")
7714 elseif g:netrw_list_hide != ""
7715 " append sfxpat to non-empty list
7716 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7717 else
7718 " set hiding list to sfxpat
7719 let g:netrw_list_hide= sfxpat
7720 endif
7721 endfor
7722
7723 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007724 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007725" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7726 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007727 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007728 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007729 endif
7730
7731" call Dret("s:NetrwMarkHideSfx")
7732endfun
7733
7734" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007735" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7736" Uses the global markfilelist
7737fun! s:NetrwMarkFileGrep(islocal)
7738" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007739 let svpos = winsaveview()
7740" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007742 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007743
7744 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007745" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007746 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007747" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007748 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007749 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007750" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007751 let netrwmarkfilelist= "*"
7752 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007753
Bram Moolenaarff034192013-04-24 18:51:19 +02007754 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007755" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007756 call inputsave()
7757 let pat= input("Enter pattern: ","")
7758 call inputrestore()
7759 let patbang = ""
7760 if pat =~ '^!'
7761 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007762 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007763 endif
7764 if pat =~ '^\i'
7765 let pat = escape(pat,'/')
7766 let pat = '/'.pat.'/'
7767 else
7768 let nonisi = pat[0]
7769 endif
7770
7771 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007773 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007774 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007776 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007777" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7778 return
7779 endtry
7780 echo "(use :cn, :cp to navigate, :Rex to return)"
7781
7782 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007783" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7784 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007785
7786 if exists("nonisi")
7787 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007789 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007790 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007791 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007792 endif
7793
7794" call Dret("s:NetrwMarkFileGrep")
7795endfun
7796
7797" ---------------------------------------------------------------------
7798" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7799" uses the global marked file list
7800" s:netrwmfloc= 0: target directory is remote
7801" = 1: target directory is local
7802fun! s:NetrwMarkFileMove(islocal)
7803" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007804 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007805 let curbufnr = bufnr("%")
7806
7807 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007808 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007809 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007810" call Dret("s:NetrwMarkFileMove")
7811 return
7812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007813" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007814
Bram Moolenaar446cb832008-06-24 21:56:24 +00007815 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007816 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817" call Dret("s:NetrwMarkFileCopy 0")
7818 return 0
7819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821
7822 if a:islocal && s:netrwmftgt_islocal
7823 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007824" call Decho("move from local to local",'~'.expand("<slnum>"))
7825" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007826 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007827 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7828" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7829 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007831 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007832" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007833 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007834 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007835" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007836 if g:netrw_localmovecmd =~ '\s'
7837 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7838 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7839 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007840" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007841 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007842 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 endif
7845 else
7846 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007848 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007849 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007850 if g:netrw_keepdir
7851 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7852 let fname= b:netrw_curdir."/".fname
7853 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007854 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 let fname= substitute(fname,'/','\\','g')
7856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007857" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007858 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007859 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007861 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 +01007862 else
7863 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7864 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007865 break
7866 endif
7867 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007868
7869 elseif a:islocal && !s:netrwmftgt_islocal
7870 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("move from local to remote",'~'.expand("<slnum>"))
7872" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007873 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007874 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007875" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007876 for fname in mflist
7877 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7878 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7879 endfor
7880 unlet mflist
7881
7882 elseif !a:islocal && s:netrwmftgt_islocal
7883 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("move from remote to local",'~'.expand("<slnum>"))
7885" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007886 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007887 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889 for fname in mflist
7890 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7891 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7892 endfor
7893 unlet mflist
7894
7895 elseif !a:islocal && !s:netrwmftgt_islocal
7896 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7898" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007899 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007900 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007901" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902 for fname in mflist
7903 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7904 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7905 endfor
7906 unlet mflist
7907 endif
7908
7909 " -------
7910 " cleanup
7911 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007912" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007913
7914 " remove markings from local buffer
7915 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7916
7917 " refresh buffers
7918 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007920 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 endif
7922 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007924 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007925 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007926 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007927" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007928 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007929 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007930
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931" call Dret("s:NetrwMarkFileMove")
7932endfun
7933
7934" ---------------------------------------------------------------------
7935" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7936" using the hardcopy command. Local marked-file list only.
7937fun! s:NetrwMarkFilePrint(islocal)
7938" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7939 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007940
7941 " sanity check
7942 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007943 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007944" call Dret("s:NetrwMarkFilePrint")
7945 return
7946 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007947" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7948 let curdir= s:NetrwGetCurdir(a:islocal)
7949
Bram Moolenaar446cb832008-06-24 21:56:24 +00007950 if exists("s:netrwmarkfilelist_{curbufnr}")
7951 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007952 call s:NetrwUnmarkList(curbufnr,curdir)
7953 for fname in netrwmarkfilelist
7954 if a:islocal
7955 if g:netrw_keepdir
7956 let fname= s:ComposePath(curdir,fname)
7957 endif
7958 else
7959 let fname= curdir.fname
7960 endif
7961 1split
7962 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007963" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007964 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007965" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007966 hardcopy
7967 q
7968 endfor
7969 2match none
7970 endif
7971" call Dret("s:NetrwMarkFilePrint")
7972endfun
7973
7974" ---------------------------------------------------------------------
7975" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7976" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007977" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978fun! s:NetrwMarkFileRegexp(islocal)
7979" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7980
7981 " get the regular expression
7982 call inputsave()
7983 let regexp= input("Enter regexp: ","","file")
7984 call inputrestore()
7985
7986 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007987 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007988" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007991 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007992 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007993 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007994 else
7995 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007996 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007997 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007998" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007999
8000 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008001 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008002 if fname =~ '^'.fnameescape(curdir)
8003" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8004 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8005 else
8006" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8007 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8008 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008009 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008010
8011 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008012" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013
8014 " convert displayed listing into a filelist
8015 let eikeep = &ei
8016 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008018 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008019" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008020 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008021 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008022 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008023 sil NetrwKeepj norm! "ap
8024 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008026 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008027 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008028 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008029 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008030 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008031 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008032 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008033 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008035 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8036 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008037 call histdel("/",-1)
8038 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008039 endif
8040 " convert regexp into the more usual glob-style format
8041 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008042" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008043 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008044 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 let filelist= getline(1,line("$"))
8046 q!
8047 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008048 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008049 endfor
8050 unlet filelist
8051 let @a = areg
8052 let &ei = eikeep
8053 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008054 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055
8056" call Dret("s:NetrwMarkFileRegexp")
8057endfun
8058
8059" ---------------------------------------------------------------------
8060" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8061" Uses the local marked file list.
8062fun! s:NetrwMarkFileSource(islocal)
8063" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8064 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008065
8066 " sanity check
8067 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008068 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008069" call Dret("s:NetrwMarkFileSource")
8070 return
8071 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008072" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8073 let curdir= s:NetrwGetCurdir(a:islocal)
8074
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 if exists("s:netrwmarkfilelist_{curbufnr}")
8076 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008077 call s:NetrwUnmarkList(curbufnr,curdir)
8078 for fname in netrwmarkfilelist
8079 if a:islocal
8080 if g:netrw_keepdir
8081 let fname= s:ComposePath(curdir,fname)
8082 endif
8083 else
8084 let fname= curdir.fname
8085 endif
8086 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008087" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008088 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008089 endfor
8090 2match none
8091 endif
8092" call Dret("s:NetrwMarkFileSource")
8093endfun
8094
8095" ---------------------------------------------------------------------
8096" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8097" Uses the global markfilelist
8098fun! s:NetrwMarkFileTag(islocal)
8099" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008100 let svpos = winsaveview()
8101" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008102 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008103 let curbufnr = bufnr("%")
8104
Bram Moolenaarff034192013-04-24 18:51:19 +02008105 " sanity check
8106 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008107 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008108" call Dret("s:NetrwMarkFileTag")
8109 return
8110 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008111" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008112
Bram Moolenaar446cb832008-06-24 21:56:24 +00008113 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008114" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8115 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 call s:NetrwUnmarkAll()
8117
8118 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008119
8120" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8121 call system(g:netrw_ctags." ".netrwmarkfilelist)
8122 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8124 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008125
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008127 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008128 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 let curdir= b:netrw_curdir
8130 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008131 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008133" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008134 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008135 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 wq!
8137 endif
8138 2match none
8139 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008140" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8141 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142 endif
8143
8144" call Dret("s:NetrwMarkFileTag")
8145endfun
8146
8147" ---------------------------------------------------------------------
8148" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008149" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008150" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008152" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008153fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008154" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8155 let svpos = winsaveview()
8156" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008157 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 let hadtgt = exists("s:netrwmftgt")
8159 if !exists("w:netrw_bannercnt")
8160 let w:netrw_bannercnt= b:netrw_bannercnt
8161 endif
8162
8163 " set up target
8164 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008165" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008166 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8167 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008168" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008169 unlet s:netrwmftgt s:netrwmftgt_islocal
8170 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008171 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008172 endif
8173 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008174" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8175 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008176" call Dret("s:NetrwMarkFileTgt : removed target")
8177 return
8178 else
8179 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008181 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008182
8183 else
8184 " get word under cursor.
8185 " * If directory, use it for the target.
8186 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008187" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008188 let curword= s:NetrwGetWord()
8189 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008190 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008191 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008192" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008193 elseif !a:islocal && tgtdir =~ '/$'
8194 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008195" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196 else
8197 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008198" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199 endif
8200 endif
8201 if a:islocal
8202 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8203 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205 endif
8206 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8209 endif
8210 let s:netrwmftgt_islocal= a:islocal
8211
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008212 " need to do refresh so that the banner will be updated
8213 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008214 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008215" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008216 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008218" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008219 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008220 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8221 else
8222 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8223 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008224" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8225 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008226 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008227 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228 endif
8229
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8231" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008232" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8233endfun
8234
8235" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008236" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8237fun! s:NetrwGetCurdir(islocal)
8238" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8239
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008240 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8242" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8243 elseif !exists("b:netrw_curdir")
8244 let b:netrw_curdir= getcwd()
8245" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8246 endif
8247
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008248" 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 +01008249 if b:netrw_curdir !~ '\<\a\{3,}://'
8250 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008251" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008252 if g:netrw_keepdir == 0
8253 call s:NetrwLcd(curdir)
8254 endif
8255 endif
8256
8257" call Dret("s:NetrwGetCurdir <".curdir.">")
8258 return b:netrw_curdir
8259endfun
8260
8261" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008262" s:NetrwOpenFile: query user for a filename and open it {{{2
8263fun! s:NetrwOpenFile(islocal)
8264" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008265 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008266 call inputsave()
8267 let fname= input("Enter filename: ")
8268 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008269" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8270
8271 " determine if Lexplore is in use
8272 if exists("t:netrw_lexbufnr")
8273 " check if t:netrw_lexbufnr refers to a netrw window
8274" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8275 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8276 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8277" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8278 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8279 exe "NetrwKeepj e ".fnameescape(fname)
8280 let @@= ykeep
8281" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8282 endif
8283 endif
8284
8285 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008286 if fname !~ '[/\\]'
8287 if exists("b:netrw_curdir")
8288 if exists("g:netrw_quiet")
8289 let netrw_quiet_keep = g:netrw_quiet
8290 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008291 let g:netrw_quiet = 1
8292 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008293 let s:rexposn_{bufnr("%")}= winsaveview()
8294" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008295 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008296 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008297 else
8298 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8299 endif
8300 if exists("netrw_quiet_keep")
8301 let g:netrw_quiet= netrw_quiet_keep
8302 else
8303 unlet g:netrw_quiet
8304 endif
8305 endif
8306 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008307 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008308 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008309 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008310" call Dret("s:NetrwOpenFile")
8311endfun
8312
8313" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008314" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8315" For the mapping to this function be made via
8316" netrwPlugin, you'll need to have had
8317" g:netrw_usetab set to non-zero.
8318fun! netrw#Shrink()
8319" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8320 let curwin = winnr()
8321 let wiwkeep = &wiw
8322 set wiw=1
8323
8324 if &ft == "netrw"
8325 if winwidth(0) > g:netrw_wiw
8326 let t:netrw_winwidth= winwidth(0)
8327 exe "vert resize ".g:netrw_wiw
8328 wincmd l
8329 if winnr() == curwin
8330 wincmd h
8331 endif
8332" call Decho("vert resize 0",'~'.expand("<slnum>"))
8333 else
8334 exe "vert resize ".t:netrw_winwidth
8335" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8336 endif
8337
8338 elseif exists("t:netrw_lexbufnr")
8339 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8340 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8341 let t:netrw_winwidth= winwidth(0)
8342 exe "vert resize ".g:netrw_wiw
8343 wincmd l
8344 if winnr() == curwin
8345 wincmd h
8346 endif
8347" call Decho("vert resize 0",'~'.expand("<slnum>"))
8348 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8349 exe "vert resize ".t:netrw_winwidth
8350" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8351 else
8352 call netrw#Lexplore(0,0)
8353 endif
8354
8355 else
8356 call netrw#Lexplore(0,0)
8357 endif
8358 let wiw= wiwkeep
8359
8360" call Dret("netrw#Shrink")
8361endfun
8362
8363" ---------------------------------------------------------------------
8364" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8365fun! s:NetSortSequence(islocal)
8366" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8367
8368 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008369 let svpos= winsaveview()
8370" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008371 call inputsave()
8372 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8373 call inputrestore()
8374
8375 " refresh the listing
8376 let g:netrw_sort_sequence= newsortseq
8377 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008378" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8379 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008380 let @@= ykeep
8381
8382" call Dret("NetSortSequence")
8383endfun
8384
8385" ---------------------------------------------------------------------
8386" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8387" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008388" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008389fun! s:NetrwUnmarkList(curbufnr,curdir)
8390" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8391
8392 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008393 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8395 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8396 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8397 call remove(s:netrwmarkfilelist,idx) " remove from global list
8398 endfor
8399 if s:netrwmarkfilelist == []
8400 unlet s:netrwmarkfilelist
8401 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008402
Bram Moolenaar446cb832008-06-24 21:56:24 +00008403 " getting rid of the local marked-file lists is easy
8404 unlet s:netrwmarkfilelist_{a:curbufnr}
8405 endif
8406 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8407 unlet s:netrwmarkfilemtch_{a:curbufnr}
8408 endif
8409 2match none
8410" call Dret("s:NetrwUnmarkList")
8411endfun
8412
8413" ---------------------------------------------------------------------
8414" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8415fun! s:NetrwUnmarkAll()
8416" call Dfunc("s:NetrwUnmarkAll()")
8417 if exists("s:netrwmarkfilelist")
8418 unlet s:netrwmarkfilelist
8419 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008420 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 2match none
8422" call Dret("s:NetrwUnmarkAll")
8423endfun
8424
8425" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008426" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427fun! s:NetrwUnmarkAll2()
8428" call Dfunc("s:NetrwUnmarkAll2()")
8429 redir => netrwmarkfilelist_let
8430 let
8431 redir END
8432 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008433 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008434 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8435 for flist in netrwmarkfilelist_list
8436 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8437 unlet s:netrwmarkfilelist_{curbufnr}
8438 unlet s:netrwmarkfilemtch_{curbufnr}
8439 endfor
8440" call Dret("s:NetrwUnmarkAll2")
8441endfun
8442
8443" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008444" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8445"
8446" Marked files are in two types of lists:
8447" s:netrwmarkfilelist -- holds complete paths to all marked files
8448" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8449"
8450" Marked files suitable for use with 2match are in:
8451" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452fun! s:NetrwUnMarkFile(islocal)
8453" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008454 let svpos = winsaveview()
8455" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456 let curbufnr = bufnr("%")
8457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008458 " unmark marked file list
8459 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8460 if exists("s:netrwmarkfilelist")
8461" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008463 endif
8464
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008465 let ibuf= 1
8466 while ibuf < bufnr("$")
8467 if exists("s:netrwmarkfilelist_".ibuf)
8468 unlet s:netrwmarkfilelist_{ibuf}
8469 unlet s:netrwmarkfilemtch_{ibuf}
8470 endif
8471 let ibuf = ibuf + 1
8472 endwhile
8473 2match none
8474
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008476"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8477call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008478" call Dret("s:NetrwUnMarkFile")
8479endfun
8480
8481" ---------------------------------------------------------------------
8482" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8483fun! s:NetrwMenu(domenu)
8484
8485 if !exists("g:NetrwMenuPriority")
8486 let g:NetrwMenuPriority= 80
8487 endif
8488
Bram Moolenaaradc21822011-04-01 18:03:16 +02008489 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8491
8492 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008493" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008494 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008495 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8499 if g:netrw_dirhistmax > 0
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8504 else
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8506 endif
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8521 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 +01008522 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 +02008523 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8552 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>'
8553 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>'
8554 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>'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8556 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>'
8557 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>'
8558 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 +01008559 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 +02008560 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008562 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008563 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8564 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565
8566 elseif !a:domenu
8567 let s:netrwcnt = 0
8568 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008569 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008570 exe curwin."wincmd w"
8571
8572 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008573" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008574 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008575" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008576 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 endif
8578 endif
8579" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008580 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008581 endif
8582
8583endfun
8584
8585" ---------------------------------------------------------------------
8586" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8587" Used by the O maps (as <SID>NetrwObtain())
8588fun! s:NetrwObtain(islocal)
8589" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8590
Bram Moolenaar97d62492012-11-15 21:28:22 +01008591 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008592 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008593 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008594 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008595 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8596 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008597 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008599 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008600
8601" call Dret("NetrwObtain")
8602endfun
8603
8604" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008605" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8606" If there's only one window, then the window will first be split.
8607" Returns:
8608" choice = 0 : didn't have to choose
8609" choice = 1 : saved modified file in window first
8610" choice = 2 : didn't save modified file, opened window
8611" choice = 3 : cancel open
8612fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008613" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008614
Bram Moolenaar97d62492012-11-15 21:28:22 +01008615 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008616 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008617 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008618" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008619
8620 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008621 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008623" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8624" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8625 let curword = s:NetrwGetWord()
8626 let choice = 0
8627 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8628" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008629 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008631 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008632" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008633" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008634" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635
Bram Moolenaar8d043172014-01-23 14:24:41 +01008636 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637 if lastwinnr == 1
8638 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008639" 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 +02008640 " g:netrw_preview=0: preview window shown in a horizontally split window
8641 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008643 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008644 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008646 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008647 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008648 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008649 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008651 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008652 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008653 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008654" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008655
8656 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008658 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008660 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008662 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008665" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008666" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008667" call Decho("COMBAK#12: mod=".&mod)
8668
8669 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8670 " whoops -- user trying to open file in the Lexplore window.
8671 " Use Lexplore's opening-file window instead.
8672" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8673" exe g:netrw_chgwin."wincmd w"
8674 wincmd p
8675 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8676 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008677
8678 " prevwinnr: the window number of the "prev" window
8679 " prevbufnr: the buffer number of the buffer in the "prev" window
8680 " bnrcnt : the qty of windows open on the "prev" buffer
8681 let prevwinnr = winnr()
8682 let prevbufnr = bufnr("%")
8683 let prevbufname = bufname("%")
8684 let prevmod = &mod
8685 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008686" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008687 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" 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 +01008689" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690
8691 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008692 " and it doesn't appear in any other extant window, then ask the
8693 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008697" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008698 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008699" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700
8701 if bnrcnt == 1 && &hidden == 0
8702 " only one copy of the modified buffer in a window, and
8703 " hidden not set, so overwriting will lose the modified file. Ask first...
8704 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008705" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008706 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008707" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008708
8709 if choice == 1
8710 " Yes -- write file & then browse
8711 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008712 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008715 exe origwin."wincmd w"
8716 let &ei = eikeep
8717 let @@ = ykeep
8718" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 return choice
8720 endif
8721
8722 elseif choice == 2
8723 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008724" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008725 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008726
8727 else
8728 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008729" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008730 exe origwin."wincmd w"
8731 let &ei= eikeep
8732 let @@ = ykeep
8733" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734 return choice
8735 endif
8736 endif
8737 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008738 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008739 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008740" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008741
8742 " restore b:netrw_curdir (window split/enew may have lost it)
8743 let b:netrw_curdir= curdir
8744 if a:islocal < 2
8745 if a:islocal
8746 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8747 else
8748 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8749 endif
8750 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008751 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008752" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008753 return choice
8754endfun
8755
8756" ---------------------------------------------------------------------
8757" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8758" Always assumed to be local -> remote
8759" call s:NetrwUpload(filename, target)
8760" call s:NetrwUpload(filename, target, fromdirectory)
8761fun! s:NetrwUpload(fname,tgt,...)
8762" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8763
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008764 if a:tgt =~ '^\a\{3,}://'
8765 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766 else
8767 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
8771 if a:0 > 0
8772 let fromdir= a:1
8773 else
8774 let fromdir= getcwd()
8775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777
8778 if type(a:fname) == 1
8779 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008780" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008782" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8783 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8784" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 if a:tgt =~ '/$'
8786 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008787" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008788 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008790" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008791 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008792" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008793 endif
8794 q!
8795
8796 elseif type(a:fname) == 3
8797 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008798" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008799 let curdir= getcwd()
8800 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008801 if s:NetrwLcd(fromdir)
8802" call Dret("s:NetrwUpload : lcd failure")
8803 return
8804 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008805 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008806 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807 if exists("g:netrw_port") && g:netrw_port != ""
8808 let useport= " ".g:netrw_scpport." ".g:netrw_port
8809 else
8810 let useport= ""
8811 endif
8812 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8813 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814 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 +02008815 if s:NetrwLcd(curdir)
8816" call Dret("s:NetrwUpload : lcd failure")
8817 return
8818 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008819
8820 elseif a:tgt =~ '^ftp:'
8821 call s:NetrwMethod(a:tgt)
8822
8823 if b:netrw_method == 2
8824 " handle uploading a list of files via ftp+.netrc
8825 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831
8832 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835 endif
8836
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008837 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008838" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008839
Bram Moolenaaradc21822011-04-01 18:03:16 +02008840 if tgtdir == ""
8841 let tgtdir= '/'
8842 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008843 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008844" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845
8846 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8848" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 endfor
8850
8851 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008852 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 +00008853 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008854" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8855 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 endif
8857 " 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 +01008858 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008859 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8861 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8862 else
8863 bw!|q
8864 endif
8865
8866 elseif b:netrw_method == 3
8867 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8868 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008869 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008870 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008871 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872
8873 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008874 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008877 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008878" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879 endif
8880
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008881 if exists("g:netrw_uid") && g:netrw_uid != ""
8882 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008888" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008889 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008890 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008891" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893 endif
8894
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008896" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897
8898 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008899 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008900" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901 endif
8902
8903 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008904 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008905" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906 endif
8907
8908 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008909 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008910" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008911 endfor
8912
8913 " perform ftp:
8914 " -i : turns off interactive prompting from ftp
8915 " -n unix : DON'T use <.netrc>, even though it exists
8916 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008917 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008918 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008919 " 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 +01008920 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008921 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8923 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008924 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008925 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8926 let &debug = debugkeep
8927 let mod = 1
8928 else
8929 bw!|q
8930 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008931 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008932" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008933 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934 endif
8935 else
8936 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8937 endif
8938 endif
8939
8940" call Dret("s:NetrwUpload")
8941endfun
8942
8943" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008944" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945fun! s:NetrwPreview(path) range
8946" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008947" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8948" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008949 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950 NetrwKeepj call s:NetrwOptionsSave("s:")
8951 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8952 NetrwKeepj call s:NetrwOptionsSafe(1)
8953 else
8954 NetrwKeepj call s:NetrwOptionsSafe(0)
8955 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008956 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008957" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008958 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008959" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8960 if g:netrw_preview
8961 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008962 let pvhkeep = &pvh
8963 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8964 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008965" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8966 else
8967 " horizontal split
8968 let pvhkeep = &pvh
8969 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8970 let &pvh = winheight(0) - winsz
8971" 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 +02008972 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008973 " g:netrw_preview g:netrw_alto
8974 " 1 : vert 1: top -- preview window is vertically split off and on the left
8975 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8976 " 0 : 1: top -- preview window is horizontally split off and on the top
8977 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8978 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008979 " 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 +02008980 " the BufEnter event set up in netrwPlugin.vim
8981" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8982 let eikeep = &ei
8983 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008984 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008985 let &ei= eikeep
8986" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008987 if exists("pvhkeep")
8988 let &pvh= pvhkeep
8989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008990 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008991 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008992 endif
8993 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008994 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 +00008995 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008996 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008997 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008998" call Dret("NetrwPreview")
8999endfun
9000
9001" ---------------------------------------------------------------------
9002" s:NetrwRefresh: {{{2
9003fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009004" 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 +00009005 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009006 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009007" call Decho("setl ma noro",'~'.expand("<slnum>"))
9008" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009009 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009010 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9011 if !exists("w:netrw_treetop")
9012 if exists("b:netrw_curdir")
9013 let w:netrw_treetop= b:netrw_curdir
9014 else
9015 let w:netrw_treetop= getcwd()
9016 endif
9017 endif
9018 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9019 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009020
9021 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009022 let screenposn = winsaveview()
9023" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009024
9025" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9026" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9027 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009029 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009030 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009031 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009032 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009033
9034 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009035" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9036 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009037
9038 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009039 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9040 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9041" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9042 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9043 else
9044" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9045 2match none
9046 endif
9047 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048
Bram Moolenaar97d62492012-11-15 21:28:22 +01009049" restore
9050 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009051" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009052endfun
9053
9054" ---------------------------------------------------------------------
9055" s:NetrwRefreshDir: refreshes a directory by name {{{2
9056" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009057" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009059" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060 if g:netrw_fastbrowse == 0
9061 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009062" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065
9066 if tgtwin > 0
9067 " tgtwin is being displayed, so refresh it
9068 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009069" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009071 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 exe curwin."wincmd w"
9073
9074 elseif bufnr(a:dirname) > 0
9075 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009076" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9077 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078 endif
9079
9080 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009081" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009082 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083 endif
9084" call Dret("s:NetrwRefreshDir")
9085endfun
9086
9087" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009088" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9089" window number to do its editing in.
9090" Supports [count]C where the count, if present, is used to specify
9091" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009093" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009094 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009095" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009096 if a:1 == "" " :NetrwC win#
9097 let g:netrw_chgwin= winnr()
9098 else " :NetrwC
9099 let g:netrw_chgwin= a:1
9100 endif
9101 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009102 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009104 let g:netrw_chgwin= winnr()
9105 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009106 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009107" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009108endfun
9109
9110" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9112" What this function does is to compute a priority for the patterns
9113" in the g:netrw_sort_sequence. It applies a substitute to any
9114" "files" that satisfy each pattern, putting the priority / in
9115" front. An "*" pattern handles the default priority.
9116fun! s:NetrwSetSort()
9117" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009118 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009119 if w:netrw_liststyle == s:LONGLIST
9120 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9121 else
9122 let seqlist = g:netrw_sort_sequence
9123 endif
9124 " sanity check -- insure that * appears somewhere
9125 if seqlist == ""
9126 let seqlist= '*'
9127 elseif seqlist !~ '\*'
9128 let seqlist= seqlist.',*'
9129 endif
9130 let priority = 1
9131 while seqlist != ""
9132 if seqlist =~ ','
9133 let seq = substitute(seqlist,',.*$','','e')
9134 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9135 else
9136 let seq = seqlist
9137 let seqlist = ""
9138 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009139 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009140 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009142 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009144 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009145 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009146" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147
9148 " sanity check
9149 if w:netrw_bannercnt > line("$")
9150 " apparently no files were left after a Hiding pattern was used
9151" call Dret("SetSort : no files left after hiding")
9152 return
9153 endif
9154 if seq == '*'
9155 let starpriority= spriority
9156 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009158 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159 " sometimes multiple sorting patterns will match the same file or directory.
9160 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9162 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009163 endif
9164 let priority = priority + 1
9165 endwhile
9166 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009167 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9168 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009169 endif
9170
9171 " Following line associated with priority -- items that satisfy a priority
9172 " pattern get prefixed by ###/ which permits easy sorting by priority.
9173 " Sometimes files can satisfy multiple priority patterns -- only the latest
9174 " priority pattern needs to be retained. So, at this point, these excess
9175 " priority prefixes need to be removed, but not directories that happen to
9176 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009177 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9178 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009179 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009180
9181" call Dret("SetSort")
9182endfun
9183
Bram Moolenaarff034192013-04-24 18:51:19 +02009184" ---------------------------------------------------------------------
9185" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9186" Implements [count]Tb (bookhist<b>)
9187" [count]Th (bookhist<h>)
9188" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009189fun! s:NetrwSetTgt(islocal,bookhist,choice)
9190" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009191
9192 if a:bookhist == 'b'
9193 " supports choosing a bookmark as a target using a qb-generated list
9194 let choice= a:choice - 1
9195 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009196 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009197 else
9198 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9199 endif
9200
9201 elseif a:bookhist == 'h'
9202 " supports choosing a history stack entry as a target using a qb-generated list
9203 let choice= (a:choice % g:netrw_dirhistmax) + 1
9204 if exists("g:netrw_dirhist_".choice)
9205 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009206 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009207 else
9208 echomsg "Sorry, history#".a:choice." not available!"
9209 endif
9210 endif
9211
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009212 " refresh the display
9213 if !exists("b:netrw_curdir")
9214 let b:netrw_curdir= getcwd()
9215 endif
9216 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9217
Bram Moolenaarff034192013-04-24 18:51:19 +02009218" call Dret("s:NetrwSetTgt")
9219endfun
9220
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009222" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009223fun! s:NetrwSortStyle(islocal)
9224" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009225 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009226 let svpos= winsaveview()
9227" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009228
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009229 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 +01009230 NetrwKeepj norm! 0
9231 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009232" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9233 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009234
9235" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9236endfun
9237
9238" ---------------------------------------------------------------------
9239" s:NetrwSplit: mode {{{2
9240" =0 : net and o
9241" =1 : net and t
9242" =2 : net and v
9243" =3 : local and o
9244" =4 : local and t
9245" =5 : local and v
9246fun! s:NetrwSplit(mode)
9247" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9248
Bram Moolenaar97d62492012-11-15 21:28:22 +01009249 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009250 call s:SaveWinVars()
9251
9252 if a:mode == 0
9253 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009254 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009255 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009256" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009257 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009258 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009259 NetrwKeepj call s:RestoreWinVars()
9260 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 unlet s:didsplit
9262
9263 elseif a:mode == 1
9264 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009265 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009266" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 tabnew
9268 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009269 NetrwKeepj call s:RestoreWinVars()
9270 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009271 unlet s:didsplit
9272
9273 elseif a:mode == 2
9274 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009275 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009276 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009277" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009278 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009280 NetrwKeepj call s:RestoreWinVars()
9281 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009282 unlet s:didsplit
9283
9284 elseif a:mode == 3
9285 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009286 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009287 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009288" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009289 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009291 NetrwKeepj call s:RestoreWinVars()
9292 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 unlet s:didsplit
9294
9295 elseif a:mode == 4
9296 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009297 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009298 let eikeep = &ei
9299 let netrw_winnr = winnr()
9300 let netrw_line = line(".")
9301 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009302 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009303 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009304 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009305 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9306 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009307 let &ei = eikeep
9308 let netrw_curdir = s:NetrwTreeDir(0)
9309" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009310 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009311 let b:netrw_curdir = netrw_curdir
9312 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009313 NetrwKeepj call s:RestoreWinVars()
9314 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009315 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009316 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009317 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9318 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009319 let &ei= eikeep
9320 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009321 unlet s:didsplit
9322
9323 elseif a:mode == 5
9324 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009325 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009326 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009327" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009328 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009329 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 NetrwKeepj call s:RestoreWinVars()
9331 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 unlet s:didsplit
9333
9334 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009335 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009336 endif
9337
Bram Moolenaar97d62492012-11-15 21:28:22 +01009338 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009339" call Dret("s:NetrwSplit")
9340endfun
9341
9342" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009343" s:NetrwTgtMenu: {{{2
9344fun! s:NetrwTgtMenu()
9345 if !exists("s:netrw_menucnt")
9346 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009347 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009348" call Dfunc("s:NetrwTgtMenu()")
9349
9350 " the following test assures that gvim is running, has menus available, and has menus enabled.
9351 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9352 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009354 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9355 endif
9356 if !exists("s:netrw_initbookhist")
9357 call s:NetrwBookHistRead()
9358 endif
9359
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360 " try to cull duplicate entries
9361 let tgtdict={}
9362
Bram Moolenaarff034192013-04-24 18:51:19 +02009363 " target bookmarked places
9364 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009366 let cnt= 1
9367 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368 if has_key(tgtdict,bmd)
9369 let cnt= cnt + 1
9370 continue
9371 endif
9372 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009373 let ebmd= escape(bmd,g:netrw_menu_escape)
9374 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009375" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009376 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 +02009377 let cnt= cnt + 1
9378 endfor
9379 endif
9380
9381 " target directory browsing history
9382 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009383" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009384 let histcnt = 1
9385 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009386 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009387 if exists("g:netrw_dirhist_{histcnt}")
9388 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389 if has_key(tgtdict,histentry)
9390 let histcnt = histcnt + 1
9391 continue
9392 endif
9393 let tgtdict[histentry] = histcnt
9394 let ehistentry = escape(histentry,g:netrw_menu_escape)
9395" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009396 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 +02009397 endif
9398 let histcnt = histcnt + 1
9399 endwhile
9400 endif
9401 endif
9402" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009403endfun
9404
9405" ---------------------------------------------------------------------
9406" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9407" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009408fun! s:NetrwTreeDir(islocal)
9409" 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 +02009410" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009411" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9412" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9413" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009415
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009416 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009417 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009418" 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 +01009419 let treedir= s:treedir
9420 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421 unlet s:prevwinopen
9422" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009423 return treedir
9424 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009425 if exists("s:prevwinopen")
9426 unlet s:prevwinopen
9427 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009428" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009429
Bram Moolenaar8d043172014-01-23 14:24:41 +01009430 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9431 let b:netrw_curdir= getcwd()
9432 endif
9433 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009434" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009436
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009437 let s:treecurpos= winsaveview()
9438" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009439" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009440
9441 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9443" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009444" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009445
9446 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009447 let curline= substitute(getline('.'),"\t -->.*$",'','')
9448 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009449" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009450 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9452 elseif curline =~ '@$'
9453" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009454 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009455" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009456 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009458 let treedir= ""
9459 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009460" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461
9462 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9464" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009465" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009466 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009469" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9470 sil! NetrwKeepj %d _
9471" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009472 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009473" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009474" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009476" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009477
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009479" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009480" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009481
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009482 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9483" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9484" let newdir = w:netrw_treetop.'/'.potentialdir
9485" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9486" let treedir = s:NetrwTreePath(newdir)
9487" let w:netrw_treetop = newdir
9488" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9489" else
9490" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009491 if a:islocal && curline =~ '@$'
9492 if isdirectory(s:NetrwFile(potentialdir))
9493 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9494 let w:netrw_treetop = treedir
9495 endif
9496 else
9497 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9498 let treedir = s:NetrwTreePath(w:netrw_treetop)
9499 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009501" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009502
9503 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009504 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009505" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009506" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009507
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009509 return treedir
9510endfun
9511
9512" ---------------------------------------------------------------------
9513" s:NetrwTreeDisplay: recursive tree display {{{2
9514fun! s:NetrwTreeDisplay(dir,depth)
9515" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9516
9517 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009518 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519
9520 " install ../ and shortdir
9521 if a:depth == ""
9522 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009523" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009525 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 if a:dir == w:netrw_treetop
9527 let shortdir= a:dir
9528 else
9529 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9530 endif
9531 call setline(line("$")+1,a:depth.shortdir)
9532 else
9533 let shortdir= substitute(a:dir,'^.*/','','e')
9534 call setline(line("$")+1,a:depth.shortdir.'/')
9535 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009536" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009537 " append a / to dir if its missing one
9538 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539
9540 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009541 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009542" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009543
Bram Moolenaar85850f32019-07-19 22:05:51 +02009544 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9545 if g:netrw_hide == 1
9546 " hide given patterns
9547 let listhide= split(g:netrw_list_hide,',')
9548" call Decho("listhide=".string(listhide))
9549 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009550 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009551 endfor
9552
9553 elseif g:netrw_hide == 2
9554 " show given patterns (only)
9555 let listhide= split(g:netrw_list_hide,',')
9556" call Decho("listhide=".string(listhide))
9557 let entries=[]
9558 for entry in w:netrw_treedict[dir]
9559 for pat in listhide
9560 if entry =~ pat
9561 call add(entries,entry)
9562 break
9563 endif
9564 endfor
9565 endfor
9566 let w:netrw_treedict[dir]= entries
9567 endif
9568 if depth != ""
9569 " always remove "." and ".." entries when there's depth
9570 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9571 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9572 endif
9573
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009574" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009575 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009576 if dir =~ '/$'
9577 let direntry= substitute(dir.entry,'[@/]$','','e')
9578 else
9579 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9580 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009581" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009583" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009584 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009586" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9587 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9588 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9589" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009590 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009593 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594 endif
9595 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009596" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009597
Bram Moolenaar446cb832008-06-24 21:56:24 +00009598" call Dret("NetrwTreeDisplay")
9599endfun
9600
9601" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009602" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9603fun! s:NetrwRefreshTreeDict(dir)
9604" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009605 if !exists("w:netrw_treedict")
9606" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9607 return
9608 endif
9609
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009610 for entry in w:netrw_treedict[a:dir]
9611 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9612" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9613
9614 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9615" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9616 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009617 let liststar = s:NetrwGlob(direntry,'*',1)
9618 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009619 let w:netrw_treedict[direntry] = liststar + listdotstar
9620" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9621
9622 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9623" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9624 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009625 let liststar = s:NetrwGlob(direntry.'/','*',1)
9626 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009627 let w:netrw_treedict[direntry]= liststar + listdotstar
9628" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9629
9630 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9631" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9632 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009633 let liststar = s:NetrwGlob(direntry.'/','*',1)
9634 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9636
9637 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009638" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009639 endif
9640 endfor
9641" call Dret("s:NetrwRefreshTreeDict")
9642endfun
9643
9644" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009645" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009646" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009647fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009648 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009649" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9651" 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>"))
9652" 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 +00009653
9654 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009656" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009658 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009659" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 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 +02009661" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009663 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009664" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009666 if exists("w:netrw_treetop")
9667 let s:netrw_treetop= w:netrw_treetop
9668 else
9669 let w:netrw_treetop= getcwd()
9670 let s:netrw_treetop= w:netrw_treetop
9671 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674 " insure that we have a treedict, albeit empty
9675" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 let w:netrw_treedict= {}
9677 endif
9678
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009679 " update the dictionary for the current directory
9680" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009681" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009682 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009685 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686
9687 " if past banner, record word
9688 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9689 let fname= expand("<cword>")
9690 else
9691 let fname= ""
9692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9694" 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 +00009695
9696 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009697" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009698 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009700
9701 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9702 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009703" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009704 1d
9705 endwhile
9706
Bram Moolenaar13600302014-05-22 18:26:40 +02009707 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009708
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009709" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009710 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009711 endif
9712endfun
9713
9714" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009715" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009716" Normally, treetop is w:netrw_treetop, but a
9717" user of the function ( netrw#SetTreetop() )
9718" wipes that out prior to calling this function
9719fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009720" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9721 if line(".") < w:netrw_bannercnt + 2
9722 let treedir= a:treetop
9723 if treedir !~ '/$'
9724 let treedir= treedir.'/'
9725 endif
9726" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9727 return treedir
9728 endif
9729
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009730 let svpos = winsaveview()
9731" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009732 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009733" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009734 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009735" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9736 let curline= getline('.')
9737" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9738 if curline =~ '/$'
9739" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9740 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9741" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9742 elseif curline =~ '@\s\+-->'
9743" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9744 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9745 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9746" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009747 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009749 let treedir= ""
9750 endif
9751 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009752" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9753" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9755 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9756 let treedir= dirname.treedir
9757 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009759 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009760" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009761 if a:treetop =~ '/$'
9762 let treedir= a:treetop.treedir
9763 else
9764 let treedir= a:treetop.'/'.treedir
9765 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009766" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009767 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009768" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009769" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9770 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009771" call Dret("s:NetrwTreePath <".treedir.">")
9772 return treedir
9773endfun
9774
9775" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009776" s:NetrwWideListing: {{{2
9777fun! s:NetrwWideListing()
9778
9779 if w:netrw_liststyle == s:WIDELIST
9780" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9781 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009782 " cpf: characters per filename
9783 " fpl: filenames per line
9784 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009785 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009786 let dict={}
9787 " save the unnamed register and register 0-9 and a
9788 let dict.a=[getreg('a'), getregtype('a')]
9789 for i in range(0, 9)
9790 let dict[i] = [getreg(i), getregtype(i)]
9791 endfor
9792 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009794 let b:netrw_cpf= 0
9795 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009796 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009797 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9798 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009799 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009800 " restore stored registers
9801 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802" call Dret("NetrwWideListing")
9803 return
9804 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009805 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009806 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009807" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808
9809 " determine qty files per line (fpl)
9810 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9811 if w:netrw_fpl <= 0
9812 let w:netrw_fpl= 1
9813 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009814" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815
9816 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817 " fpc: files per column of wide listing
9818 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009819 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9821 let newcolstart = w:netrw_bannercnt + fpc
9822 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009824 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009825" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009826 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009827 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009828 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009829 while line("$") >= newcolstart
9830 if newcolend > line("$") | let newcolend= line("$") | endif
9831 let newcolqty= newcolend - newcolstart
9832 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009833 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009835 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009836 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009837 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009839 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009840 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009842 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009843" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009844 if @* != keepregstar | sil! let @* = keepregstar | endif
9845 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009846 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009847 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9848 NetrwKeepj call histdel("/",-1)
9849 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9850 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009851" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009852 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009853 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009854" 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 +00009855" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009856 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009857 else
9858 if hasmapto("w","n")
9859 sil! nunmap <buffer> w
9860 endif
9861 if hasmapto("b","n")
9862 sil! nunmap <buffer> b
9863 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009864 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865endfun
9866
9867" ---------------------------------------------------------------------
9868" s:PerformListing: {{{2
9869fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9871" 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 +02009872" 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>"))
9873 sil! NetrwKeepj %d _
9874" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009875
Bram Moolenaar15146672011-10-20 22:22:38 +02009876 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009878 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009879
Bram Moolenaar85850f32019-07-19 22:05:51 +02009880 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009881 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883
9884" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009885" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886" endif " Decho
9887
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9890 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009891" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9892 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893 endif
9894
9895 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009896 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897
9898 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009899 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009901 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902 if exists("g:netrw_pchk")
9903 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9904 " failure detections.
9905 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9908 endif
9909 if exists("g:netrw_pchk")
9910 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9911 else
9912 let curdir= b:netrw_curdir
9913 endif
9914 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9915 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9916 else
9917 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009918 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009919 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009920 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009921 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009923 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009924 let w:netrw_bannercnt= 1
9925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009926" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9927" 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 +00009928
Bram Moolenaar85850f32019-07-19 22:05:51 +02009929 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009930 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009931 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932 let sortby= sortby." reversed"
9933 endif
9934
9935 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009936 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009938 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009940 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009941 NetrwKeepj put ='\" Sorted by '.sortby
9942 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9944 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009946 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009947 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009948 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9949 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009950 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009951" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952" 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 +00009953 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954
Bram Moolenaar85850f32019-07-19 22:05:51 +02009955 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if g:netrw_banner
9957 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009960 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009962 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009963 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009964 endif
9965 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009967" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009968 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009971
9972 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009974" 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 +01009975 if g:netrw_list_hide != "" && g:netrw_hide
9976 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009977 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009978 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009979 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009980 endif
9981 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009983 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009984
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 Moolenaara6878372014-03-22 21:02:50 +01009986 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" 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 +01009990 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009991 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009992" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" 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 +00009994 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995
9996 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009997 if g:netrw_banner
9998 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000" 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 +010010001" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" 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 +010010003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010004
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010007 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010008 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010010 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010011 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" 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 +010010013" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10014 return
10015 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017
10018 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010019 if !exists("w:netrw_bannercnt")
10020 let w:netrw_bannercnt= 0
10021 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010022" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10023" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10024" 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 +010010025
Bram Moolenaar5c736222010-01-06 20:54:52 +010010026 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010027" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028" 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 +000010029 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010030 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010031 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010032 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010034
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010035 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010037" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010038 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010039
Bram Moolenaar5c736222010-01-06 20:54:52 +010010040 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010041" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010042 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010043 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010044 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045 else
10046 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010047 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048 endif
10049 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010050
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10054 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010055
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010056 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010057 " exten: sort by extension
10058 " The histdel(...,-1) calls remove the last search from the search history
10059" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10061 NetrwKeepj call histdel("/",-1)
10062 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10063 NetrwKeepj call histdel("/",-1)
10064 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10065 NetrwKeepj call histdel("/",-1)
10066 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10067" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010068 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010069 " normal direction sorting
10070 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10071 else
10072 " reverse direction sorting
10073 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10074 endif
10075 endif
10076 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10077 NetrwKeepj call histdel("/",-1)
10078
Bram Moolenaar446cb832008-06-24 21:56:24 +000010079 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010080 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010081" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010082 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010083" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010084 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010085 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010086" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010087 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010088 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010089" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010090 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10091 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010092 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010093 endif
10094
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010095 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010097 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010098 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010099 call histdel("/",-1)
10100 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010101 endif
10102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010103" 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 +000010104
10105 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10107" 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 +010010108 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" 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 +010010110 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" 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 +000010112
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010114 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010116 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010117 endif
10118
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010119 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010120 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10122 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010123 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10125 else
10126" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10127" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10128" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10129" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010130 endif
10131
10132 " record previous current directory
10133 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010135
10136 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10138" 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 +010010139 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" 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 +020010141 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" 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 +000010143
10144 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010146 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" 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 +010010148 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010150 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10151 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010152" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010153" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010154
Bram Moolenaar8d043172014-01-23 14:24:41 +010010155 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10157" 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 +010010158" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10159 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010160 unlet s:treecurpos
10161 endif
10162
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" 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>"))
10164" 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 +000010165" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10166endfun
10167
10168" ---------------------------------------------------------------------
10169" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010170fun! s:SetupNetrwStatusLine(statline)
10171" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10172
10173 if !exists("s:netrw_setup_statline")
10174 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010175" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010176
10177 if !exists("s:netrw_users_stl")
10178 let s:netrw_users_stl= &stl
10179 endif
10180 if !exists("s:netrw_users_ls")
10181 let s:netrw_users_ls= &laststatus
10182 endif
10183
10184 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010185 let dict={}
10186 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187 redir @a
10188 try
10189 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010190 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010191 if &bg == "dark"
10192 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10193 else
10194 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10195 endif
10196 endtry
10197 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010198 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010199 endif
10200
10201 " set up status line (may use User9 highlighting)
10202 " insure that windows have a statusline
10203 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010204 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010205 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010206" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010207 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010208
10209" call Dret("SetupNetrwStatusLine : stl=".&stl)
10210endfun
10211
Bram Moolenaar85850f32019-07-19 22:05:51 +020010212" =========================================
10213" Remote Directory Browsing Support: {{{1
10214" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010215
10216" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010217" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10218" This function assumes that a long listing will be received. Size, time,
10219" and reverse sorts will be requested of the server but not otherwise
10220" enforced here.
10221fun! s:NetrwRemoteFtpCmd(path,listcmd)
10222" 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 +010010223" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010224 " sanity check: {{{3
10225 if !exists("w:netrw_method")
10226 if exists("b:netrw_method")
10227 let w:netrw_method= b:netrw_method
10228 else
10229 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10230" call Dret("NetrwRemoteFtpCmd")
10231 return
10232 endif
10233 endif
10234
10235 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10236 let ffkeep= &ff
10237 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010238" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010239
10240 " clear off any older non-banner lines " {{{3
10241 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010242" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10243 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010244
10245 ".........................................
10246 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10247 " ftp + <.netrc>: Method #2
10248 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010249 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 endif
10251 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010252 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010253" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010254 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010255 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010256" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010258" 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>"))
10259 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 +010010260 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010261" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10262 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 +010010263 endif
10264
10265 ".........................................
10266 elseif w:netrw_method == 3 " {{{3
10267 " ftp + machine,id,passwd,filename: Method #3
10268 setl ff=unix
10269 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010270 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010271 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010272 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 endif
10274
10275 " handle userid and password
10276 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010277" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010278 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10279 call NetUserPass("ftp:".host)
10280 endif
10281 if exists("g:netrw_uid") && g:netrw_uid != ""
10282 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010283 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010284 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010285 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010286 endif
10287 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010288 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010289 endif
10290 endif
10291
10292 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010293 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 endif
10295 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010296 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010297" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010298 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010299 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010300
10301 " perform ftp:
10302 " -i : turns off interactive prompting from ftp
10303 " -n unix : DON'T use <.netrc>, even though it exists
10304 " -n win32: quit being obnoxious about password
10305 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010306" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010307 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010308" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010309" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10310" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010311 endif
10312
10313 ".........................................
10314 elseif w:netrw_method == 9 " {{{3
10315 " sftp username@machine: Method #9
10316 " s:netrw_sftp_cmd
10317 setl ff=unix
10318
10319 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010320 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010321" call Dret("NetrwRemoteFtpCmd")
10322 return
10323
10324 ".........................................
10325 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010326 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 endif
10328
10329 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010330 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010331 sil! NetrwKeepj %s/\r$//e
10332 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010333 endif
10334 if a:listcmd == "dir"
10335 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010336 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10337 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10338 NetrwKeepj call histdel("/",-1)
10339 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010340 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 +010010341 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10342 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 endif
10344 endif
10345
10346 " ftp's listing doesn't seem to include ./ or ../ " {{{3
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 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010352 exe 'NetrwKeepj '.w:netrw_bannercnt
10353 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010354 endif
10355
10356 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010357 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010358" call Dret("NetrwRemoteFtpCmd")
10359endfun
10360
10361" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362" s:NetrwRemoteListing: {{{2
10363fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010364" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010365
Bram Moolenaara6878372014-03-22 21:02:50 +010010366 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10367 let w:netrw_bannercnt= s:bannercnt
10368 endif
10369 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010370 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010371 endif
10372
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010374
Bram Moolenaar446cb832008-06-24 21:56:24 +000010375 " sanity check:
10376 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010377" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010378 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010379" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380 if !exists("g:netrw_quiet")
10381 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10382 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010383 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010384" call Dret("s:NetrwRemoteListing -1")
10385 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010386 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010387
Bram Moolenaar8d043172014-01-23 14:24:41 +010010388 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010391 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010392 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 +000010393 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010394 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 +000010395 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010396 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010397
Bram Moolenaar85850f32019-07-19 22:05:51 +020010398 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010399" call Dret("s:NetrwRemoteListing -1")
10400 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010401 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010402" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010403
Bram Moolenaar446cb832008-06-24 21:56:24 +000010404 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010405" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406 let w:netrw_method= b:netrw_method
10407 endif
10408
Bram Moolenaar13600302014-05-22 18:26:40 +020010409 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010410 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010412 let s:method = "ftp"
10413 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010414 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010416 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 let listcmd= g:netrw_ftp_sizelist_cmd
10418 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010421" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422
Bram Moolenaara6878372014-03-22 21:02:50 +010010423 " report on missing file or directory messages
10424 if search('[Nn]o such file or directory\|Failed to change directory')
10425 let mesg= getline(".")
10426 if exists("w:netrw_bannercnt")
10427 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010428 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010429 setl noma
10430 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010431 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010432 call netrw#ErrorMsg(s:WARNING,mesg,96)
10433" call Dret("s:NetrwRemoteListing : -1")
10434 return -1
10435 endif
10436
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010437 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 +000010438 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010439" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441
10442 " cleanup
10443 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010444 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10445 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010446 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010447 sil! NetrwKeepj %s/\r$//e
10448 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010449
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010450 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010453 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010454" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010456" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010457 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 exe "sil! NetrwKeepj ".line1
10460 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010462" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10466 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10470 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10471 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10472 NetrwKeepj call histdel("/",-1)
10473 NetrwKeepj call histdel("/",-1)
10474 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 endif
10476 endif
10477
Bram Moolenaar13600302014-05-22 18:26:40 +020010478 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010484" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10485 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010487 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10488 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10489 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10490 NetrwKeepj call histdel("/",-1)
10491 NetrwKeepj call histdel("/",-1)
10492 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010494 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10495 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010496 endif
10497 else
10498 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010499" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010500 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10503 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10504" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 endif
10506 endif
10507
10508 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010509 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010510" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010511 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10512 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010513 endif
10514 endif
10515
10516 if w:netrw_liststyle == s:LONGLIST
10517 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519
10520 if s:method == "ftp"
10521 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010523 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010526 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010528 sil! NetrwKeepj 1
10529 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 let line2= line(".")
10531 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010532 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010533 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 endif
10535 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010536 exe "sil! NetrwKeepj ".line1
10537 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010538 endif
10539
10540 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010541" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010542 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 +000010543 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010545 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010546 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010547 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10548 NetrwKeepj call histdel("/",-1)
10549 NetrwKeepj call histdel("/",-1)
10550 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010551 endif
10552 endif
10553
10554" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010555" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010557
10558" call Dret("s:NetrwRemoteListing 0")
10559 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010560endfun
10561
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562" ---------------------------------------------------------------------
10563" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10564fun! s:NetrwRemoteRm(usrhost,path) range
10565" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010567 let svpos= winsaveview()
10568" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569
10570 let all= 0
10571 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10572 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574 for fname in s:netrwmarkfilelist_{bufnr("%")}
10575 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010576 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010578 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579 let all= 1
10580 endif
10581 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010582 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583
10584 else
10585 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587
10588 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010589 let keepsol = &l:sol
10590 setl nosol
10591 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592
10593 " remove multiple files and directories
10594 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010595 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010597 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010599 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 let all= 1
10601 endif
10602 let ctr= ctr + 1
10603 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 endif
10606
10607 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010608" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010609 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010610" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10611 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010612
10613" call Dret("s:NetrwRemoteRm")
10614endfun
10615
10616" ---------------------------------------------------------------------
10617" s:NetrwRemoteRmFile: {{{2
10618fun! s:NetrwRemoteRmFile(path,rmfile,all)
10619" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10620
10621 let all= a:all
10622 let ok = ""
10623
10624 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10625 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627 if !all
10628 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 call inputsave()
10631 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10632 call inputrestore()
10633 echohl NONE
10634 if ok == ""
10635 let ok="no"
10636 endif
10637 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010638 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 let all= 1
10640 endif
10641 endif
10642
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010643 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644" 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 +000010645 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010647 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648 if path =~ '^\a\{3,}://'
10649 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010651 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10653 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010654" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010658 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 let ok="q"
10660 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010661 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10663" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10664" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672 if v:shell_error != 0
10673 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010674 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 +010010675 else
10676 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10677 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010678 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 endif
10683 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010684 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010686 endif
10687
10688 else
10689 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691 if !all
10692 call inputsave()
10693 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10694 call inputrestore()
10695 if ok == ""
10696 let ok="no"
10697 endif
10698 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010699 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700 let all= 1
10701 endif
10702 endif
10703
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010704 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010705 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010706 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010707 else
10708 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010709 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10710" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010711 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713
10714 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010715" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10716 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10717" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010718 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010720
10721 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010722 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010723 endif
10724 endif
10725 endif
10726
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010727 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010729 endif
10730 endif
10731
10732" call Dret("s:NetrwRemoteRmFile ".ok)
10733 return ok
10734endfun
10735
10736" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737" s:NetrwRemoteRename: rename a remote file or directory {{{2
10738fun! s:NetrwRemoteRename(usrhost,path) range
10739" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10740
10741 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010742 let svpos = winsaveview()
10743" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010744 let ctr = a:firstline
10745 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10746
10747 " rename files given by the markfilelist
10748 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10749 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010750" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010751 if exists("subfrom")
10752 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010753" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 else
10755 call inputsave()
10756 let newname= input("Moving ".oldname." to : ",oldname)
10757 call inputrestore()
10758 if newname =~ '^s/'
10759 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10760 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10761 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763 endif
10764 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010767 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010768 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769 let oldname= s:ShellEscape(a:path.oldname)
10770 let newname= s:ShellEscape(a:path.newname)
10771" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010772 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 endif
10774
10775 endfor
10776 call s:NetrwUnMarkFile(1)
10777
10778 else
10779
10780 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010781 let keepsol= &l:sol
10782 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010783 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010784 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010785
10786 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010787" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010788
10789 call inputsave()
10790 let newname= input("Moving ".oldname." to : ",oldname)
10791 call inputrestore()
10792
10793 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10794 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10795 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010796 let oldname= s:ShellEscape(a:path.oldname)
10797 let newname= s:ShellEscape(a:path.newname)
10798" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010799 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010800 endif
10801
10802 let ctr= ctr + 1
10803 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010804 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010805 endif
10806
10807 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010808 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010809" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10810 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010811
10812" call Dret("NetrwRemoteRename")
10813endfun
10814
Bram Moolenaar85850f32019-07-19 22:05:51 +020010815" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010816" Local Directory Browsing Support: {{{1
10817" ==========================================
10818
10819" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010820" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821" Should accept: file://localhost/etc/fstab
10822" file:///etc/fstab
10823" file:///c:/WINDOWS/clock.avi
10824" file:///c|/WINDOWS/clock.avi
10825" file://localhost/c:/WINDOWS/clock.avi
10826" file://localhost/c|/WINDOWS/clock.avi
10827" file://c:/foo.txt
10828" file:///c:/foo.txt
10829" 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 +020010830fun! netrw#FileUrlEdit(fname)
10831" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010832 let fname = a:fname
10833 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010834" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010837 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010838 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 endif
10844 endif
10845 let fname2396 = netrw#RFC2396(fname)
10846 let fname2396e= fnameescape(fname2396)
10847 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010848 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010850 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010851" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010852 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10853 endif
10854 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010855
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010856" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10857" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010858 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010859 exe 'NetrwKeepj keepalt edit '.plainfname
10860 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10861
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010862" 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 +020010863" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010864 exe "sil doau BufReadPost ".fname2396e
10865endfun
10866
10867" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010868" netrw#LocalBrowseCheck: {{{2
10869fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010870 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010871 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10872 "
10873 " unfortunate interaction -- split window debugging can't be used here, must use
10874 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10875 " another call to LocalBrowseCheck() when attempts to write
10876 " to the DBG buffer are made.
10877 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878 " The &ft == "netrw" test was installed because the BufEnter event
10879 " would hit when re-entering netrw windows, creating unexpected
10880 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010881" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010882" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883" 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 +010010884 " getting E930: Cannot use :redir inside execute
10885"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10887" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010888
Bram Moolenaar97d62492012-11-15 21:28:22 +010010889 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890 if isdirectory(s:NetrwFile(a:dirname))
10891" 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 +010010892
Bram Moolenaar97d62492012-11-15 21:28:22 +010010893 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10895" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.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 Moolenaar446cb832008-06-24 21:56:24 +000010898 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010900 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010901
Bram Moolenaar5c736222010-01-06 20:54:52 +010010902 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010904 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010905 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010907" 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 +010010908" call Dret("netrw#LocalBrowseCheck")
10909 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010910 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010911
Bram Moolenaar85850f32019-07-19 22:05:51 +020010912 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010913 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10914 " AND IF the listing style is not a tree listing
10915 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010917 let ibuf = 1
10918 let buflast = bufnr("$")
10919 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10921 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010922 endif
10923 let ibuf= ibuf + 1
10924 endwhile
10925 endif
10926 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010927" 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>"))
10928" 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 +000010929 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010930" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010931endfun
10932
10933" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010934" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010935" performed any shell command. The idea is to cause all local-browsing
10936" buffers to be refreshed after a user has executed some shell command,
10937" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010938fun! s:LocalBrowseRefresh()
10939" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010940" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10941" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010942
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943 " determine which buffers currently reside in a tab
10944 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010945" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 return
10947 endif
10948 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010949" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010950 return
10951 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010952 if !empty(getcmdwintype())
10953 " cannot move away from cmdline window, see :h E11
10954 return
10955 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010956 if exists("s:netrw_events") && s:netrw_events == 1
10957 " s:LocalFastBrowser gets called (indirectly) from a
10958 let s:netrw_events= 2
10959" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10960 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010961 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 let itab = 1
10963 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010964 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 while itab <= tabpagenr("$")
10966 let buftablist = buftablist + tabpagebuflist()
10967 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010968 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10971" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10973 " | refresh any netrw window
10974 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010975 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010976 let ibl = 0
10977 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010978" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10980 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010981 " (ibuf not shown in a current window AND
10982 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010983" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10984 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 continue
10988 elseif index(tabpagebuflist(),ibuf) != -1
10989 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010992 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010993 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10994 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10995 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10996 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010998 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10999 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11000 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011001 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011002 endif
11003 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011006" call Decho("restore window: win_gotoid(".curwinid.")")
11007 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011008 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011009
Bram Moolenaara6878372014-03-22 21:02:50 +010011010" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011011endfun
11012
11013" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11015"
11016" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011018" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11019" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011020" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011021"
11022" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11023" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011024" (re-using a buffer may not be as accurate)
11025"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011026" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011027" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11028" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11029" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11030" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011031fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011032" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11033" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11034" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11035" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036
11037 " initialize browselist, a list of buffer numbers that the local browser has used
11038 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040 let s:netrw_browselist= []
11041 endif
11042
11043 " append current buffer to fastbrowse list
11044 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011047" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011048 endif
11049
11050 " enable autocmd events to handle refreshing/removing local browser buffers
11051 " If local browse buffer is currently showing: refresh it
11052 " If local browse buffer is currently hidden : wipe it
11053 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11054 " =1 : medium speed, re-use directory listing for remote only
11055 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011056 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11057 let s:netrw_events= 1
11058 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011060 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011061" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011062 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011063 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011066 endif
11067 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068
11069 " user must have changed fastbrowse to its fast setting, so remove
11070 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011071 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 unlet s:netrw_events
11074 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011075 au!
11076 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011077 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078 endif
11079
Bram Moolenaar85850f32019-07-19 22:05:51 +020011080" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081endfun
11082
11083" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011084" s:LocalListing: does the job of "ls" for local directories {{{2
11085fun! s:LocalListing()
11086" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11088" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11089" 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 +010011090
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011091" 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
11092" 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
11093" 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 +010011094
11095 " get the list of files contained in the current directory
11096 let dirname = b:netrw_curdir
11097 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011098 let filelist = s:NetrwGlob(dirname,"*",0)
11099 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011100" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011101
Nir Lichtman1e34b952024-05-08 19:19:34 +020011102 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011103" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011104 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11105 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109 endif
11110
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011111" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011113" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011114
11115 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11116 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11117 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11119" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" 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 +010011122
11123 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho(" ",'~'.expand("<slnum>"))
11125" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126
11127 if getftype(filename) == "link"
11128 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 let pfile= filename."@"
11131
11132 elseif getftype(filename) == "socket"
11133 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011134" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011135 let pfile= filename."="
11136
11137 elseif getftype(filename) == "fifo"
11138 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011140 let pfile= filename."|"
11141
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011143 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 let pfile= filename."/"
11146
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011148 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011149 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11150 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 let pfile= filename."*"
11153 else
11154 " normal file
11155 let pfile= filename
11156 endif
11157 elseif executable(filename)
11158 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011159" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011160 let pfile= filename."*"
11161 else
11162 " normal file
11163 let pfile= filename
11164 endif
11165
11166 else
11167 " normal file
11168 let pfile= filename
11169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011170" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171
11172 if pfile =~ '//$'
11173 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011174" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011175 endif
11176 let pfile= strpart(pfile,dirnamelen)
11177 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011178" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11179" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011180
11181 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011182 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11183 let sz = getfsize(filename)
11184 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11185 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011186
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011187 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011188 let sz= s:NetrwHumanReadable(sz)
11189 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011190 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011191 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011192" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193 endif
11194
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011195 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011197 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011198" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011199" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011200 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011201 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011202" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011204 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011205
11206 elseif g:netrw_sort_by =~ "^s"
11207 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011208" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011209" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011210 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011211 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011212" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011213 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011214 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011215
11216 else
11217 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011218" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011219" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011220 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011221 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011222" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011223 endfor
11224
11225 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011226 sil! NetrwKeepj g/^$/d
11227 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011228 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011229" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011230 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11231
11232" call Dret("s:LocalListing")
11233endfun
11234
11235" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011236" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11237fun! s:NetrwLocalExecute(cmd)
11238" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11239 let ykeep= @@
11240 " sanity check
11241 if !executable(a:cmd)
11242 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11243 let @@= ykeep
11244" call Dret("s:NetrwLocalExecute")
11245 return
11246 endif
11247
11248 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011249" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011250 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011251" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011252
11253 " strip any ansi escape sequences off
11254 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11255
11256 " show user the result(s)
11257 echomsg result
11258 let @@= ykeep
11259
11260" call Dret("s:NetrwLocalExecute")
11261endfun
11262
11263" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011264" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011265fun! s:NetrwLocalRename(path) range
11266" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11267
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011268 if !exists("w:netrw_bannercnt")
11269 let w:netrw_bannercnt= b:netrw_bannercnt
11270 endif
11271
Bram Moolenaar97d62492012-11-15 21:28:22 +010011272 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011273 let ykeep = @@
11274 let ctr = a:firstline
11275 let svpos = winsaveview()
11276 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011277" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011278
11279 " rename files given by the markfilelist
11280 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11281 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011282" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011283 if exists("subfrom")
11284 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011285" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011286 else
11287 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011288 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011289 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011290 if newname =~ ''
11291 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11292 let newname = substitute(newname,'^.*','','')
11293 elseif newname =~ ''
11294 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11295 let newname = substitute(newname,'[^/]*','','')
11296 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011297 if newname =~ '^s/'
11298 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11299 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011300" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011301 let newname = substitute(oldname,subfrom,subto,'')
11302 endif
11303 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011304 if !all && filereadable(newname)
11305 call inputsave()
11306 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11307 call inputrestore()
11308 if response == "all"
11309 let all= 1
11310 elseif response != "y" && response != "yes"
11311 " refresh the directory
11312" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11313 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11314" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11315 NetrwKeepj call winrestview(svpos)
11316 let @@= ykeep
11317" call Dret("NetrwLocalRename")
11318 return
11319 endif
11320 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011321 call rename(oldname,newname)
11322 endfor
11323 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011324
Bram Moolenaar97d62492012-11-15 21:28:22 +010011325 else
11326
11327 " attempt to rename files/directories
11328 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011329 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011330
11331 " sanity checks
11332 if line(".") < w:netrw_bannercnt
11333 let ctr= ctr + 1
11334 continue
11335 endif
11336 let curword= s:NetrwGetWord()
11337 if curword == "./" || curword == "../"
11338 let ctr= ctr + 1
11339 continue
11340 endif
11341
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011342 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011343 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011344" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011345
11346 call inputsave()
11347 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11348 call inputrestore()
11349
11350 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011351" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011352
11353 let ctr= ctr + 1
11354 endwhile
11355 endif
11356
11357 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011358" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011359 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011360" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11361 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011362 let @@= ykeep
11363
11364" call Dret("NetrwLocalRename")
11365endfun
11366
11367" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011368" s:NetrwLocalRm: {{{2
11369fun! s:NetrwLocalRm(path) range
11370" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011371" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011372
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011373 if !exists("w:netrw_bannercnt")
11374 let w:netrw_bannercnt= b:netrw_bannercnt
11375 endif
11376
Bram Moolenaar446cb832008-06-24 21:56:24 +000011377 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011378 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379 let ret = 0
11380 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011381 let svpos = winsaveview()
11382" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383
11384 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11385 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011386" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011387 for fname in s:netrwmarkfilelist_{bufnr("%")}
11388 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011389 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011391 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011392 let all= 1
11393 endif
11394 endfor
11395 call s:NetrwUnMarkFile(1)
11396
11397 else
11398 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011399" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011400
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011401 let keepsol= &l:sol
11402 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011403 let ctr = a:firstline
11404 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011405 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406
11407 " sanity checks
11408 if line(".") < w:netrw_bannercnt
11409 let ctr= ctr + 1
11410 continue
11411 endif
11412 let curword= s:NetrwGetWord()
11413 if curword == "./" || curword == "../"
11414 let ctr= ctr + 1
11415 continue
11416 endif
11417 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011418 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011420 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011421 let all= 1
11422 endif
11423 let ctr= ctr + 1
11424 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011425 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426 endif
11427
11428 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011429" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011431 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011432" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11433 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011434 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011435 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011436
11437" call Dret("s:NetrwLocalRm")
11438endfun
11439
11440" ---------------------------------------------------------------------
11441" s:NetrwLocalRmFile: remove file fname given the path {{{2
11442" Give confirmation prompt unless all==1
11443fun! s:NetrwLocalRmFile(path,fname,all)
11444" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011445
Bram Moolenaar446cb832008-06-24 21:56:24 +000011446 let all= a:all
11447 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011448 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011449 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011451
11452 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11453 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011454" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455 if !all
11456 echohl Statement
11457 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011458 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011459 call inputrestore()
11460 echohl NONE
11461 if ok == ""
11462 let ok="no"
11463 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011464" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011465 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011466" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011467 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 let all= 1
11469 endif
11470 endif
11471
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011472 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011473 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011474" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011475 endif
11476
11477 else
11478 " attempt to remove directory
11479 if !all
11480 echohl Statement
11481 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011482 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011483 call inputrestore()
11484 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11485 if ok == ""
11486 let ok="no"
11487 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011488 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011489 let all= 1
11490 endif
11491 endif
11492 let rmfile= substitute(rmfile,'[\/]$','','e')
11493
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011494 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011495 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011496 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011497 endif
11498 endif
11499 endif
11500
11501" call Dret("s:NetrwLocalRmFile ".ok)
11502 return ok
11503endfun
11504
Bram Moolenaar85850f32019-07-19 22:05:51 +020011505" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011506" Support Functions: {{{1
11507
Bram Moolenaar488c6512005-08-11 20:09:58 +000011508" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011509" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11510" 0: marked file list of current buffer
11511" 1: marked file target
11512fun! netrw#Access(ilist)
11513 if a:ilist == 0
11514 if exists("s:netrwmarkfilelist_".bufnr('%'))
11515 return s:netrwmarkfilelist_{bufnr('%')}
11516 else
11517 return "no-list-buf#".bufnr('%')
11518 endif
11519 elseif a:ilist == 1
11520 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011521 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011522endfun
11523
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524" ---------------------------------------------------------------------
11525" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11526fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011527 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011528endfun
11529
Bram Moolenaara6878372014-03-22 21:02:50 +010011530" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011531" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11532" I expect this function to be used in
11533" :PChkAssert netrw#Expose("netrwmarkfilelist")
11534" for example.
11535fun! netrw#Expose(varname)
11536" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011537 if exists("s:".a:varname)
11538 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011539" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011540 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011541" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011542 if type(retval) == 3
11543 let retval = copy(retval)
11544 let i = 0
11545 while i < len(retval)
11546 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11547 let i = i + 1
11548 endwhile
11549 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011550" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011551 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011552 else
11553" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011554 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011555 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011556" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011557 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011558 endif
11559
11560" call Dret("netrw#Expose ".string(retval))
11561 return retval
11562endfun
11563
11564" ---------------------------------------------------------------------
11565" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11566fun! netrw#Modify(varname,newvalue)
11567" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11568 exe "let s:".a:varname."= ".string(a:newvalue)
11569" call Dret("netrw#Modify")
11570endfun
11571
11572" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011573" netrw#RFC2396: converts %xx into characters {{{2
11574fun! netrw#RFC2396(fname)
11575" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011576 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011577" call Dret("netrw#RFC2396 ".fname)
11578 return fname
11579endfun
11580
11581" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011582" netrw#UserMaps: supports user-specified maps {{{2
11583" see :help function()
11584"
11585" g:Netrw_UserMaps is a List with members such as:
11586" [[keymap sequence, function reference],...]
11587"
11588" The referenced function may return a string,
11589" refresh : refresh the display
11590" -other- : this string will be executed
11591" or it may return a List of strings.
11592"
11593" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011594" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011595" Related functions:
11596" netrw#Expose(varname) -- see s:varname variables
11597" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11598" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11599fun! netrw#UserMaps(islocal)
11600" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11601" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11602
11603 " set up usermaplist
11604 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11605" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11606 for umap in g:Netrw_UserMaps
11607" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11608" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11609 " if umap[0] is a string and umap[1] is a string holding a function name
11610 if type(umap[0]) == 1 && type(umap[1]) == 1
11611" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11612 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11613 else
11614 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11615 endif
11616 endfor
11617 endif
11618" call Dret("netrw#UserMaps")
11619endfun
11620
11621" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011622" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11623fun! netrw#WinPath(path)
11624" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011625 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011626 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011627 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011628 " remove trailing slash (Win95)
11629 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11630 " remove escaped spaces
11631 let path = substitute(path, '\ ', ' ', 'g')
11632 " convert slashes to backslashes
11633 let path = substitute(path, '/', '\', 'g')
11634 else
11635 let path= a:path
11636 endif
11637" call Dret("netrw#WinPath <".path.">")
11638 return path
11639endfun
11640
11641" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011642" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11643fun! s:StripTrailingSlash(path)
11644 " remove trailing slash
11645 return substitute(a:path, '[/\\]$', '', 'g')
11646endfun
11647
Travis Sheltone34d0e32024-07-30 21:08:56 +020011648" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011649" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11650" cb : bl2mf=0 add marked files to buffer list
11651" cB : bl2mf=1 use bufferlist to mark files
11652" (mnemonic: cb = copy (marked files) to buffer list)
11653fun! s:NetrwBadd(islocal,bl2mf)
11654" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11655 if a:bl2mf
11656 " cB: add buffer list to marked files
11657 redir => bufl
11658 ls
11659 redir END
11660 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11661 for fname in bufl
11662 call s:NetrwMarkFile(a:islocal,fname)
11663 endfor
11664 else
11665 " cb: add marked files to buffer list
11666 for fname in s:netrwmarkfilelist_{bufnr("%")}
11667" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11668 exe "badd ".fnameescape(fname)
11669 endfor
11670 let curbufnr = bufnr("%")
11671 let curdir = s:NetrwGetCurdir(a:islocal)
11672 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11673 endif
11674" call Dret("s:NetrwBadd")
11675endfun
11676
11677" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011678" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11679fun! s:ComposePath(base,subdir)
11680" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11681
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011682 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011683" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011684 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011685 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011686 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011687 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011688 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011689 endif
11690
Bram Moolenaar85850f32019-07-19 22:05:51 +020011691 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011692 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011694 let ret= a:subdir
11695
Nir Lichtman1e34b952024-05-08 19:19:34 +020011696 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011698 if a:base =~ '[/\\]$'
11699 let ret= a:base.a:subdir
11700 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011701 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011702 endif
11703
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704 elseif a:base =~ '^\a\{3,}://'
11705" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011706 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11707 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11708 if a:subdir == '../'
11709 if curpath =~ '[^/]/[^/]\+/$'
11710 let curpath= substitute(curpath,'[^/]\+/$','','')
11711 else
11712 let curpath=""
11713 endif
11714 let ret= urlbase.curpath
11715 else
11716 let ret= urlbase.curpath.a:subdir
11717 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11719" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11720" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011721
11722 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011723" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011724 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11725 if a:base =~ '^//'
11726 " keeping initial '//' for the benefit of network share listing support
11727 let ret= '/'.ret
11728 endif
11729 let ret= simplify(ret)
11730 endif
11731
11732" call Dret("s:ComposePath ".ret)
11733 return ret
11734endfun
11735
11736" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011737" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11738" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11739fun! s:DeleteBookmark(fname)
11740" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11741 call s:MergeBookmarks()
11742
11743 if exists("g:netrw_bookmarklist")
11744 let indx= index(g:netrw_bookmarklist,a:fname)
11745 if indx == -1
11746 let indx= 0
11747 while indx < len(g:netrw_bookmarklist)
11748 if g:netrw_bookmarklist[indx] =~ a:fname
11749 call remove(g:netrw_bookmarklist,indx)
11750 let indx= indx - 1
11751 endif
11752 let indx= indx + 1
11753 endwhile
11754 else
11755 " remove exact match
11756 call remove(g:netrw_bookmarklist,indx)
11757 endif
11758 endif
11759
11760" call Dret("s:DeleteBookmark")
11761endfun
11762
11763" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011764" s:FileReadable: o/s independent filereadable {{{2
11765fun! s:FileReadable(fname)
11766" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11767
11768 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011769 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011770 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011771 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011772 endif
11773
11774" call Dret("s:FileReadable ".ret)
11775 return ret
11776endfun
11777
11778" ---------------------------------------------------------------------
11779" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11780" Places correct suffix on end of temporary filename,
11781" using the suffix provided with fname
11782fun! s:GetTempfile(fname)
11783" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11784
11785 if !exists("b:netrw_tmpfile")
11786 " get a brand new temporary filename
11787 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011788" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011789
Bram Moolenaarc236c162008-07-13 17:41:49 +000011790 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011791" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011792
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011794 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11795" 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 +010011796 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011797" call Dret("s:GetTempfile getcwd<".getcwd().">")
11798 return ""
11799 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011802 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011803" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011804
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011806 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011807 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011808 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 if !exists("+shellslash") || !&ssl
11810 let tmpfile = substitute(tmpfile,'/','\','g')
11811 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011813 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 endif
11815 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 else
11818 " re-use temporary filename
11819 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011820" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011821 endif
11822
11823 " use fname's suffix for the temporary file
11824 if a:fname != ""
11825 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011827 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011829 elseif a:fname =~ '.txz$'
11830 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 else
11832 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11833 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011837 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011838" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11840 endif
11841 endif
11842
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011843" 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 +000011844" call Dret("s:GetTempfile <".tmpfile.">")
11845 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011846endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847
11848" ---------------------------------------------------------------------
11849" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011850" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011851fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011852" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011853 if s:user == ""
11854 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11855 else
11856 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11857 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011858 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011859 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011860 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011861 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011862 else
11863 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11864 endif
11865" call Dret("s:MakeSshCmd <".sshcmd.">")
11866 return sshcmd
11867endfun
11868
11869" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011870" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11871fun! s:MakeBookmark(fname)
11872" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11873
11874 if !exists("g:netrw_bookmarklist")
11875 let g:netrw_bookmarklist= []
11876 endif
11877
11878 if index(g:netrw_bookmarklist,a:fname) == -1
11879 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011880 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011881 call add(g:netrw_bookmarklist,a:fname.'/')
11882 elseif a:fname !~ '/'
11883 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11884 else
11885 call add(g:netrw_bookmarklist,a:fname)
11886 endif
11887 call sort(g:netrw_bookmarklist)
11888 endif
11889
11890" call Dret("s:MakeBookmark")
11891endfun
11892
11893" ---------------------------------------------------------------------
11894" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11895fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011896" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 " get bookmarks from .netrwbook file
11898 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011899 if filereadable(s:NetrwFile(savefile))
11900" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011901 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011903 NetrwKeepj call delete(savefile)
11904 endif
11905" call Dret("s:MergeBookmarks")
11906endfun
11907
11908" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011909" s:NetrwBMShow: {{{2
11910fun! s:NetrwBMShow()
11911" call Dfunc("s:NetrwBMShow()")
11912 redir => bmshowraw
11913 menu
11914 redir END
11915 let bmshowlist = split(bmshowraw,'\n')
11916 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011917 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918 if bmshowfuncs != []
11919 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011920 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011921 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011922 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011924 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011925" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11926endfun
11927
11928" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011929" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011930fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011931 if !exists("w:netrw_liststyle")
11932 let w:netrw_liststyle= g:netrw_liststyle
11933 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011934" 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 +020011935
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011936" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11937
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938 if &ft != "netrw"
11939 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11940 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011941" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011942
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011943 elseif g:netrw_cursor == 8
11944 if w:netrw_liststyle == s:WIDELIST
11945 setl cursorline
11946 setl cursorcolumn
11947 else
11948 setl cursorline
11949 endif
11950 elseif g:netrw_cursor == 7
11951 setl cursorline
11952 elseif g:netrw_cursor == 6
11953 if w:netrw_liststyle == s:WIDELIST
11954 setl cursorline
11955 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011956 elseif g:netrw_cursor == 4
11957 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011958" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011959 setl cursorline
11960 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011961
11962 elseif g:netrw_cursor == 3
11963 " thin-long-tree: cursorline, user's cursorcolumn
11964 " wide : cursorline, cursorcolumn
11965 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011967 setl cursorline
11968 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011969 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970" 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 +020011971 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972 endif
11973
11974 elseif g:netrw_cursor == 2
11975 " thin-long-tree: cursorline, user's cursorcolumn
11976 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011977" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011978 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979
11980 elseif g:netrw_cursor == 1
11981 " thin-long-tree: user's cursorline, user's cursorcolumn
11982 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011983 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011984" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011985 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011987" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011988 endif
11989
11990 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011991 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011992" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011993 let &l:cursorline = s:netrw_usercul
11994 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011995 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011996
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011997" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011999endfun
12000
12001" ---------------------------------------------------------------------
12002" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12003fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012004" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012005 if exists("s:netrw_usercul")
12006 let &l:cursorline = s:netrw_usercul
12007 endif
12008 if exists("s:netrw_usercuc")
12009 let &l:cursorcolumn = s:netrw_usercuc
12010 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012011" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012012" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12013endfun
12014
Christian Brabandt62f7b552024-06-23 20:23:40 +020012015" s:RestoreRegister: restores all registers given in the dict {{{2
12016fun! s:RestoreRegister(dict)
12017 for [key, val] in items(a:dict)
12018 if key == 'unnamed'
12019 let key = ''
12020 endif
12021 call setreg(key, val[0], val[1])
12022 endfor
12023endfun
12024
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012025" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012026" s:NetrwDelete: Deletes a file. {{{2
12027" Uses Steve Hall's idea to insure that Windows paths stay
12028" acceptable. No effect on Unix paths.
12029" Examples of use: let result= s:NetrwDelete(path)
12030fun! s:NetrwDelete(path)
12031" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12032
Bram Moolenaar5c736222010-01-06 20:54:52 +010012033 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012034 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 if exists("+shellslash")
12036 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012037 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012038 let result = delete(path)
12039 let &shellslash = sskeep
12040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012041" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012042 let result= delete(path)
12043 endif
12044 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012045" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012046 let result= delete(path)
12047 endif
12048 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012049 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012050 endif
12051
12052" call Dret("s:NetrwDelete ".result)
12053 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012054endfun
12055
12056" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012057" s:NetrwBufRemover: removes a buffer that: {{{2s
12058" has buffer-id > 1
12059" is unlisted
12060" is unnamed
12061" does not appear in any window
12062fun! s:NetrwBufRemover(bufid)
12063" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12064" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12065" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12066" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12067" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12068
yasuda4dbb2662023-10-04 20:50:35 +020012069 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012070" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012071 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012072 endif
12073
12074" call Dret("s:NetrwBufRemover")
12075endfun
12076
12077" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012078" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012079fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012080" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012081" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012082
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012083 " Clean out the last buffer:
12084 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12085 " If so, delete it.
12086 call s:NetrwBufRemover(bufnr("$"))
12087
Bram Moolenaar446cb832008-06-24 21:56:24 +000012088 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012089" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012090 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12091 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12092 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12093 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12094 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12095 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12096 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12097 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12098 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12099 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12100 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12101 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12102 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12103 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12104 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12105 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12106
Bram Moolenaar85850f32019-07-19 22:05:51 +020012107 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012108" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012109 " when tree listing uses file TreeListing... a new buffer is made.
12110 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012111 " COMBAK: this causes a problem, see P43
12112" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012113 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012114 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012115 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012116" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012117 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012118
Bram Moolenaar446cb832008-06-24 21:56:24 +000012119 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012120" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012121 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12122 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12123 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12124 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12125 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12126 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12127 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12128 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12129 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12130 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12131 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12132 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12133 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12134 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12135 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12136 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12137
Bram Moolenaar5c736222010-01-06 20:54:52 +010012138 if a:0 > 0
12139 let b:netrw_curdir= a:1
12140 if b:netrw_curdir =~ '/$'
12141 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012142 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012143 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012144 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012145 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12146 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012147 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012148 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012149 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012150 endif
12151 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012152 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12153 let &l:bexpr = "netrw#BalloonHelp()"
12154 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012155
Bram Moolenaar8d043172014-01-23 14:24:41 +010012156" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012157endfun
12158
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012159" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012160" s:NetrwExe: executes a string using "!" {{{2
12161fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012162" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012163 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012165 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12166 set shell& shellcmdflag& shellxquote& shellxescape&
12167 set shellquote& shellpipe& shellredir& shellslash&
12168 exe a:cmd
12169 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12170 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012171" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012172 exe a:cmd
12173 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012174 if v:shell_error
12175 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12176 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012177" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012178endfun
12179
12180" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012181" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12182fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012183 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012184" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012185 let curbuf = bufnr("%")
12186 let curwin = winnr()
12187 let iwin = 1
12188 while iwin <= winnr("$")
12189 exe iwin."wincmd w"
12190 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12191 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12192 let winvars= w:
12193 break
12194 endif
12195 let iwin= iwin + 1
12196 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012197 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012198 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012199" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012200 for k in keys(winvars)
12201 let w:{k}= winvars[k]
12202 endfor
12203 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012204" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012205 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012206endfun
12207
Bram Moolenaara6878372014-03-22 21:02:50 +010012208" ---------------------------------------------------------------------
12209" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012210" Returns: 0=success
12211" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012212fun! s:NetrwLcd(newdir)
12213" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012214" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012215
Bram Moolenaar85850f32019-07-19 22:05:51 +020012216 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012217 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012218 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 catch /^Vim\%((\a\+)\)\=:E344/
12220 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12221 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012222 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012223 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12224 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012225 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012226 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12227 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012228 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 endif
12230 endif
12231 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012232 let err472= 1
12233 endtry
12234
12235 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012236 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12237 if exists("w:netrw_prvdir")
12238 let a:newdir= w:netrw_prvdir
12239 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012240 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012241" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012242 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012243" 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 +010012244 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012246" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12247 return -1
12248 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012249
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012250" call Decho("getcwd <".getcwd().">")
12251" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012252" call Dret("s:NetrwLcd 0")
12253 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012254endfun
12255
Bram Moolenaar9964e462007-05-05 17:54:07 +000012256" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012257" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12258" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12259fun! s:NetrwSaveWordPosn()
12260" call Dfunc("NetrwSaveWordPosn()")
12261 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12262" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12263endfun
12264
12265" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012266" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12267" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12268fun! s:NetrwHumanReadable(sz)
12269" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12270
12271 if g:netrw_sizestyle == 'h'
12272 if a:sz >= 1000000000
12273 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12274 elseif a:sz >= 10000000
12275 let sz = printf("%d",a:sz/1000000)."m"
12276 elseif a:sz >= 1000000
12277 let sz = printf("%.1f",a:sz/1000000.0)."m"
12278 elseif a:sz >= 10000
12279 let sz = printf("%d",a:sz/1000)."k"
12280 elseif a:sz >= 1000
12281 let sz = printf("%.1f",a:sz/1000.0)."k"
12282 else
12283 let sz= a:sz
12284 endif
12285
12286 elseif g:netrw_sizestyle == 'H'
12287 if a:sz >= 1073741824
12288 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12289 elseif a:sz >= 10485760
12290 let sz = printf("%d",a:sz/1048576)."M"
12291 elseif a:sz >= 1048576
12292 let sz = printf("%.1f",a:sz/1048576.0)."M"
12293 elseif a:sz >= 10240
12294 let sz = printf("%d",a:sz/1024)."K"
12295 elseif a:sz >= 1024
12296 let sz = printf("%.1f",a:sz/1024.0)."K"
12297 else
12298 let sz= a:sz
12299 endif
12300
12301 else
12302 let sz= a:sz
12303 endif
12304
12305" call Dret("s:NetrwHumanReadable ".sz)
12306 return sz
12307endfun
12308
12309" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012310" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12311" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12312fun! s:NetrwRestoreWordPosn()
12313" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012314 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012315" call Dret("NetrwRestoreWordPosn")
12316endfun
12317
12318" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012319" s:RestoreBufVars: {{{2
12320fun! s:RestoreBufVars()
12321" call Dfunc("s:RestoreBufVars()")
12322
12323 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12324 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12325 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12326 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12327 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12328 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12329
12330" call Dret("s:RestoreBufVars")
12331endfun
12332
12333" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012334" s:RemotePathAnalysis: {{{2
12335fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012336" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012337
Bram Moolenaara6878372014-03-22 21:02:50 +010012338 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012339 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012340 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012341 let s:user = substitute(a:dirname,dirpat,'\3','')
12342 let s:machine = substitute(a:dirname,dirpat,'\4','')
12343 let s:port = substitute(a:dirname,dirpat,'\5','')
12344 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012345 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012346 if s:machine =~ '@'
12347 let dirpat = '^\(.*\)@\(.\{-}\)$'
12348 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12349 let s:machine = substitute(s:machine,dirpat,'\2','')
12350 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012351
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012352" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12353" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12354" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12355" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12356" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12357" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012358
12359" call Dret("s:RemotePathAnalysis")
12360endfun
12361
12362" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012363" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12364" Returns status
12365" Runs system() on
12366" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012367" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012368fun! s:RemoteSystem(cmd)
12369" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12370 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012371 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 +000012372 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012373 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012374 else
12375 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12376 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12377 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012378 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012379 else
12380 let cmd= cmd.' '
12381 endif
12382 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012383" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012384 let ret= system(cmd)
12385 endif
12386" call Dret("s:RemoteSystem ".ret)
12387 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388endfun
12389
12390" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012391" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012392fun! s:RestoreWinVars()
12393" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012394 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012395 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12396 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12397 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12398 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12399 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12400 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12401 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12402 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12403 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12404 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12405 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12406 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012407 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12408 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012409 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12410 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12411 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12412" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012413endfun
12414
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012415" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012416" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12417"
12418" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12419" is true) and a command, :Rexplore, which call this function.
12420"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012421" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012422"
12423" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012424fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012425 if exists("s:netrwdrag")
12426 return
12427 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012428" 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 +010012429" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12430" 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 +010012431
12432 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012433 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012434" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012435 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012436 unlet w:netrw_rexfile
12437" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012438 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012439" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012440" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12441" 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 +020012442 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012443
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012444 " ---------------------------
12445 " :Rex issued while in a file
12446 " ---------------------------
12447
Bram Moolenaara6878372014-03-22 21:02:50 +010012448 " record current file so :Rex can return to it from netrw
12449 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012450" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012451
12452 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012453" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012454 return
12455 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012456" 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 +020012457 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012458 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012459 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012460 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012461 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012462 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012463 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012464 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012465 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012466" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12467 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012468" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12469 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012470 if exists("s:rexposn_".bufnr('%'))
12471 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012472 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012474" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012475 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012476
Bram Moolenaar85850f32019-07-19 22:05:51 +020012477 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12478 if exists("s:explore_match")
12479 exe "2match netrwMarkFile /".s:explore_match."/"
12480 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012481 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012482
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012483" 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 +010012484" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012485endfun
12486
12487" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012488" s:SaveBufVars: save selected b: variables to s: variables {{{2
12489" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012490fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012491" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012492
12493 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12494 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12495 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12496 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12497 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12498 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12499
12500" call Dret("s:SaveBufVars")
12501endfun
12502
12503" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012504" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12505fun! s:SavePosn(posndict)
12506" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12507
Bram Moolenaar85850f32019-07-19 22:05:51 +020012508 if !exists("a:posndict[bufnr('%')]")
12509 let a:posndict[bufnr("%")]= []
12510 endif
12511" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12512 call add(a:posndict[bufnr("%")],winsaveview())
12513" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012514
12515" call Dret("s:SavePosn posndict")
12516 return a:posndict
12517endfun
12518
12519" ---------------------------------------------------------------------
12520" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12521fun! s:RestorePosn(posndict)
12522" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012523 if exists("a:posndict")
12524 if has_key(a:posndict,bufnr("%"))
12525" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12526 let posnlen= len(a:posndict[bufnr("%")])
12527 if posnlen > 0
12528 let posnlen= posnlen - 1
12529" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12530 call winrestview(a:posndict[bufnr("%")][posnlen])
12531 call remove(a:posndict[bufnr("%")],posnlen)
12532" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12533 endif
12534 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012535 endif
12536" call Dret("s:RestorePosn")
12537endfun
12538
12539" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012540" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012541fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012542" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012543 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12544 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12545 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12546 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12547 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12548 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12549 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12550 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12551 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12552 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12553 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12554 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12555 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12556 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12557 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12558 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12559 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12560 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12561" call Dret("s:SaveWinVars")
12562endfun
12563
12564" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012565" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012566" To allow separate windows to have their own activities, such as
12567" Explore **/pattern, several variables have been made window-oriented.
12568" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012569" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012570" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012571fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012572" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012573 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12574 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12575 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12576 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12577 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12578 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12579 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12580 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12581 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12582 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12583" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012584endfun
12585
12586" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012587" s:SetRexDir: set directory for :Rexplore {{{2
12588fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012589" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012590 let w:netrw_rexdir = a:dirname
12591 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012592 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012593" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12594" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012595" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012596" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012597" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012598endfun
12599
12600" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012601" s:ShowLink: used to modify thin and tree listings to show links {{{2
12602fun! s:ShowLink()
12603" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012604" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12605" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012606 if exists("b:netrw_curdir")
12607 norm! $?\a
12608 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12609 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012610" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12611" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12612" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12613 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012614 let dirlen = strlen(b:netrw_curdir)
12615 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012616" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012617 endif
12618 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012619" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12620" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012621 setl noro ma
12622 call setline(".",modline)
12623 setl ro noma nomod
12624 endif
12625" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12626endfun
12627
12628" ---------------------------------------------------------------------
12629" s:ShowStyle: {{{2
12630fun! s:ShowStyle()
12631 if !exists("w:netrw_liststyle")
12632 let liststyle= g:netrw_liststyle
12633 else
12634 let liststyle= w:netrw_liststyle
12635 endif
12636 if liststyle == s:THINLIST
12637 return s:THINLIST.":thin"
12638 elseif liststyle == s:LONGLIST
12639 return s:LONGLIST.":long"
12640 elseif liststyle == s:WIDELIST
12641 return s:WIDELIST.":wide"
12642 elseif liststyle == s:TREELIST
12643 return s:TREELIST.":tree"
12644 else
12645 return 'n/a'
12646 endif
12647endfun
12648
12649" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12651" Solution from Nicolai Weibull, vim docs (:help strlen()),
12652" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012653fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012654" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12655
12656 if v:version >= 703 && exists("*strdisplaywidth")
12657 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012658
Bram Moolenaar8d043172014-01-23 14:24:41 +010012659 elseif type(g:Align_xstrlen) == 1
12660 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12661 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012662
Bram Moolenaar8d043172014-01-23 14:24:41 +010012663 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012664 " number of codepoints (Latin a + combining circumflex is two codepoints)
12665 " (comment from TM, solution from NW)
12666 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012667
Bram Moolenaar8d043172014-01-23 14:24:41 +010012668 elseif g:Align_xstrlen == 2
12669 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12671 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012672 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012673
Bram Moolenaar8d043172014-01-23 14:24:41 +010012674 elseif g:Align_xstrlen == 3
12675 " virtual length (counting, for instance, tabs as anything between 1 and
12676 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012677 " preceded by lam, one otherwise, etc.)
12678 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012679 let modkeep= &l:mod
12680 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012681 call setline(line("."),a:x)
12682 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012683 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012684 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012685 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012686
Bram Moolenaar446cb832008-06-24 21:56:24 +000012687 else
12688 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012689 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012690 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012691" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012692 return ret
12693endfun
12694
12695" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012696" s:ShellEscape: shellescape(), or special windows handling {{{2
12697fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012698 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012699 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12700 endif
12701 let f = a:0 > 0 ? a:1 : 0
12702 return shellescape(a:s, f)
12703endfun
12704
12705" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012706" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012707fun! s:TreeListMove(dir)
12708" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012709 let curline = getline('.')
12710 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12711 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12712 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12713 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12714 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12715 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12716" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12717" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12718" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12719" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12720" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12721 " COMBAK : need to handle when on a directory
12722 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012723 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012725 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012726 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012727" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012728 elseif a:dir == '[]' && nxtline != ''
12729 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012730" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012731 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12732 if nl != 0
12733 NetrwKeepj norm! k
12734 else
12735 NetrwKeepj norm! G
12736 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012737" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012738 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012739 endif
12740
12741" call Dret("s:TreeListMove")
12742endfun
12743
12744" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012745" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12746" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12747" can't be called except via emenu. But due to locale, that menu line may not be called
12748" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12749fun! s:UpdateBuffersMenu()
12750" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012751 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012752 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012753 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012754 catch /^Vim\%((\a\+)\)\=:E/
12755 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012756 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012757 endtry
12758 endif
12759" call Dret("s:UpdateBuffersMenu")
12760endfun
12761
12762" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012763" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012764" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012765fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012766" call Dfunc("s:UseBufWinVars()")
12767 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012768 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12769 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12770 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12771 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12772 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12773 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12774 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12775 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12776 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 +000012777" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012778endfun
12779
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012780" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012781" s:UserMaps: supports user-defined UserMaps {{{2
12782" * calls a user-supplied funcref(islocal,curdir)
12783" * interprets result
12784" See netrw#UserMaps()
12785fun! s:UserMaps(islocal,funcname)
12786" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12787
12788 if !exists("b:netrw_curdir")
12789 let b:netrw_curdir= getcwd()
12790 endif
12791 let Funcref = function(a:funcname)
12792 let result = Funcref(a:islocal)
12793
12794 if type(result) == 1
12795 " if result from user's funcref is a string...
12796" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12797 if result == "refresh"
12798" call Decho("refreshing display",'~'.expand("<slnum>"))
12799 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12800 elseif result != ""
12801" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12802 exe result
12803 endif
12804
12805 elseif type(result) == 3
12806 " if result from user's funcref is a List...
12807" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12808 for action in result
12809 if action == "refresh"
12810" call Decho("refreshing display",'~'.expand("<slnum>"))
12811 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12812 elseif action != ""
12813" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12814 exe action
12815 endif
12816 endfor
12817 endif
12818
12819" call Dret("s:UserMaps")
12820endfun
12821
Bram Moolenaar85850f32019-07-19 22:05:51 +020012822" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012823" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012824" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012825let &cpo= s:keepcpo
12826unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012827
Bram Moolenaar85850f32019-07-19 22:05:51 +020012828" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012829" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012830" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012831" vim:ts=8 fdm=marker