blob: 300729eba8d8fb4e56f6f1ec2d9c4f4a3cb03e34 [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
6" Last Change:
7" 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 Brabandtf9ca1392024-02-19 20:37:11 +010017" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000018" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010019" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000020" Permission is hereby granted to use and distribute this code,
21" with or without modifications, provided that this copyright
22" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000023" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000024" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000025" expressed or implied. By using this plugin, you agree that
26" in no event will the copyright holder be liable for any damages
27" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010028"
29" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
30" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
31"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020032"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000033"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000034" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000035" (James 1:22 RSV)
36" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000037" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000038if &cp || exists("g:loaded_netrw")
39 finish
40endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020041
42" Check that vim has patches that netrw requires.
43" Patches needed for v7.4: 1557, and 213.
44" (netrw will benefit from vim's having patch#656, too)
45let s:needspatches=[1557,213]
46if exists("s:needspatches")
47 for ptch in s:needspatches
48 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
49 if !exists("s:needpatch{ptch}")
50 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
51 endif
52 let s:needpatch{ptch}= 1
53 finish
54 endif
55 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020056endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020057
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010058let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000059if !exists("s:NOTE")
60 let s:NOTE = 0
61 let s:WARNING = 1
62 let s:ERROR = 2
63endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000064
Bram Moolenaar1afcace2005-11-25 19:54:28 +000065let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010066setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020067"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010068"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010069"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000070
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000071" ======================
72" Netrw Variables: {{{1
73" ======================
74
Bram Moolenaar071d4272004-06-13 20:20:40 +000075" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020076" netrw#ErrorMsg: {{{2
77" 0=note = s:NOTE
78" 1=warning = s:WARNING
79" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010080" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
81" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
82" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010083" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020084fun! netrw#ErrorMsg(level,msg,errnum)
85" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
86
87 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020088" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020089 return
90 endif
91
92 if a:level == 1
93 let level= "**warning** (netrw) "
94 elseif a:level == 2
95 let level= "**error** (netrw) "
96 else
97 let level= "**note** (netrw) "
98 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010099" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200100
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200101 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
102 " use popup window
103 if type(a:msg) == 3
104 let msg = [level]+a:msg
105 else
106 let msg= level.a:msg
107 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200108 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200109 let s:popuperr_text= ""
110 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200111 " (default) netrw creates a one-line window to show error/warning
112 " messages (reliably displayed)
113
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100114 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100116" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117
118 " getting messages out reliably is just plain difficult!
119 " This attempt splits the current window, creating a one line window.
120 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100121" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200122 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100123" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100125 if type(a:msg) == 3
126 for msg in a:msg
127 NetrwKeepj call setline(line("$")+1,level.msg)
128 endfor
129 else
130 NetrwKeepj call setline(line("$")+1,level.a:msg)
131 endif
132 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100134" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 bo 1split
136 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200137 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100139 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100140" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100142 if type(a:msg) == 3
143 for msg in a:msg
144 NetrwKeepj call setline(line("$")+1,level.msg)
145 endfor
146 else
147 NetrwKeepj call setline(line("$"),level.a:msg)
148 endif
149 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100151" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152 if &fo !~ '[ta]'
153 syn clear
154 syn match netrwMesgNote "^\*\*note\*\*"
155 syn match netrwMesgWarning "^\*\*warning\*\*"
156 syn match netrwMesgError "^\*\*error\*\*"
157 hi link netrwMesgWarning WarningMsg
158 hi link netrwMesgError Error
159 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100160" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200161 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200162
163 else
164 " (optional) netrw will show messages using echomsg. Even if the
165 " message doesn't appear, at least it'll be recallable via :messages
166" redraw!
167 if a:level == s:WARNING
168 echohl WarningMsg
169 elseif a:level == s:ERROR
170 echohl Error
171 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100172
173 if type(a:msg) == 3
174 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100175 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100176 endfor
177 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100178 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100179 endif
180
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100181" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200182 echohl None
183 endif
184
185" call Dret("netrw#ErrorMsg")
186endfun
187
188" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100189" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100190" Loosely, varname = value.
191fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100192" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100193 if !exists(a:varname)
194 if type(a:value) == 0
195 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200196 elseif type(a:value) == 1 && a:value =~ '^[{[]'
197 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100198 elseif type(a:value) == 1
199 exe "let ".a:varname."="."'".a:value."'"
200 else
201 exe "let ".a:varname."=".a:value
202 endif
203 endif
204endfun
205
206" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000207" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200208call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000209if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100210 call s:NetrwInit("s:THINLIST",0)
211 call s:NetrwInit("s:LONGLIST",1)
212 call s:NetrwInit("s:WIDELIST",2)
213 call s:NetrwInit("s:TREELIST",3)
214 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000215endif
216
217" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200218" Default option values: {{{2
219let g:netrw_localcopycmdopt = ""
220let g:netrw_localcopydircmdopt = ""
221let g:netrw_localmkdiropt = ""
222let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200223
224" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000225" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200226if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
227 call s:NetrwInit("g:netrw_use_errorwindow",2)
228else
229 call s:NetrwInit("g:netrw_use_errorwindow",1)
230endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200231
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000232if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100233 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000234 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100235 elseif executable("curl")
236 let g:netrw_dav_cmd = "curl"
237 else
238 let g:netrw_dav_cmd = ""
239 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000241if !exists("g:netrw_fetch_cmd")
242 if executable("fetch")
243 let g:netrw_fetch_cmd = "fetch -o"
244 else
245 let g:netrw_fetch_cmd = ""
246 endif
247endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100248if !exists("g:netrw_file_cmd")
249 if executable("elinks")
250 call s:NetrwInit("g:netrw_file_cmd","elinks")
251 elseif executable("links")
252 call s:NetrwInit("g:netrw_file_cmd","links")
253 endif
254endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000255if !exists("g:netrw_ftp_cmd")
256 let g:netrw_ftp_cmd = "ftp"
257endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200258let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200259if !exists("g:netrw_ftp_options")
260 let g:netrw_ftp_options= "-i -n"
261endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000262if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100263 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100264 let g:netrw_http_cmd = "wget"
265 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100266 elseif executable("curl")
267 let g:netrw_http_cmd = "curl"
268 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200269 elseif executable("elinks")
270 let g:netrw_http_cmd = "elinks"
271 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000272 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100273 let g:netrw_http_cmd = "fetch"
274 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200275 elseif executable("links")
276 let g:netrw_http_cmd = "links"
277 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000278 else
279 let g:netrw_http_cmd = ""
280 endif
281endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100282call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100283call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100284call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
285call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200286call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200287if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200288 if executable("scp")
289 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
290 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200291 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200292 else
293 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
294 endif
295endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100296call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
297call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000298
Nir Lichtman1e34b952024-05-08 19:19:34 +0200299if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300 \ && exists("g:netrw_use_nt_rcp")
301 \ && g:netrw_use_nt_rcp
302 \ && executable( $SystemRoot .'/system32/rcp.exe')
303 let s:netrw_has_nt_rcp = 1
304 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000305else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000306 let s:netrw_has_nt_rcp = 0
307 let s:netrw_rcpmode = ''
308endif
309
310" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000311" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000312" Cygwin Detection ------- {{{3
313if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200314 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
315 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000316 else
317 let g:netrw_cygwin= 0
318 endif
319endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000320" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100321call s:NetrwInit("g:netrw_alto" , &sb)
322call s:NetrwInit("g:netrw_altv" , &spr)
323call s:NetrwInit("g:netrw_banner" , 1)
324call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200325call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100326call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200327call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_compress" , "gzip")
329call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200330if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
331 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
332 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000333endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200334call s:NetrwInit("g:netrw_cursor" , 2)
335let s:netrw_usercul = &cursorline
336let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200337"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100338call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000339" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200340call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200341call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200342call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200344call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_fastbrowse" , 1)
346call 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 +0000347if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000348 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
349 let g:netrw_ftp_list_cmd = "ls -lF"
350 let g:netrw_ftp_timelist_cmd = "ls -tlF"
351 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000352 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000353 let g:netrw_ftp_list_cmd = "dir"
354 let g:netrw_ftp_timelist_cmd = "dir"
355 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000356 endif
357endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100358call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000359" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000361if !exists("g:netrw_ignorenetrc")
362 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
363 let g:netrw_ignorenetrc= 1
364 else
365 let g:netrw_ignorenetrc= 0
366 endif
367endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100368call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000369if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100371 if exists("g:netrw_list_cmd_options")
372 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
373 else
374 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
375 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000376 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200377 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100378 if exists("g:netrw_list_cmd_options")
379 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
380 else
381 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
382 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000383 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100384" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000385 let g:netrw_list_cmd= ""
386 endif
387endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100388call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000389" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200390if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200391 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200392 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
393endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100394if !exists("g:netrw_localcmdshell")
395 let g:netrw_localcmdshell= ""
396endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000397if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200398 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399 if g:netrw_cygwin
400 let g:netrw_localcopycmd= "cp"
401 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000402 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200403 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000404 endif
405 elseif has("unix") || has("macunix")
406 let g:netrw_localcopycmd= "cp"
407 else
408 let g:netrw_localcopycmd= ""
409 endif
410endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100411if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200412 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100413 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200414 let g:netrw_localcopydircmd = "cp"
415 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100416 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000417 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200418 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100419 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200420 elseif has("unix")
421 let g:netrw_localcopydircmd = "cp"
422 let g:netrw_localcopydircmdopt= " -R"
423 elseif has("macunix")
424 let g:netrw_localcopydircmd = "cp"
425 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100426 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200427 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428 endif
429endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200430if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100431 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200432 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
433endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200434if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200435 if g:netrw_cygwin
436 call s:NetrwInit("g:netrw_localmkdir","mkdir")
437 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000438 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200439 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200440 endif
441else
442 call s:NetrwInit("g:netrw_localmkdir","mkdir")
443endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200444call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200445if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200446 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200447 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
448endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000449if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200450 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000451 if g:netrw_cygwin
452 let g:netrw_localmovecmd= "mv"
453 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000454 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200455 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000456 endif
457 elseif has("unix") || has("macunix")
458 let g:netrw_localmovecmd= "mv"
459 else
460 let g:netrw_localmovecmd= ""
461 endif
462endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100463" following serves as an example for how to insert a version&patch specific test
464"if v:version < 704 || (v:version == 704 && !has("patch1107"))
465"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100466call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
467" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000468if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000469 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000470endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000471if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000472 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
473endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000474" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100475call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
476call s:NetrwInit("g:netrw_maxfilenamelen", 32)
477call s:NetrwInit("g:netrw_menu" , 1)
478call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200479call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100480call s:NetrwInit("g:netrw_retmap" , 0)
481if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
482 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200483elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100484 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
485else
486 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000487endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_preview" , 0)
489call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100490call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100491call s:NetrwInit("g:netrw_sshport" , "-p")
492call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
493call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
494call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100495call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
496" Default values - q-s ---------- {{{3
497call s:NetrwInit("g:netrw_quickhelp",0)
498let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100499 \ "(create new) %:file d:directory",
500 \ "(windows split&open) o:horz v:vert p:preview",
501 \ "i:style qf:file info O:obtain r:reverse",
502 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
503 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
504 \ "(history) qb:list u:go up U:go down",
505 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100506" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
507call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100508if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
509 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
510else
511 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
512endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100513call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
514call s:NetrwInit("g:netrw_sort_options" , "")
515call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000516if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100517 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200518 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519 else
520 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000521 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000522endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523call s:NetrwInit("g:netrw_special_syntax" , 0)
524call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200525call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100526call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100527call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000528" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200530if !exists("g:netrw_xstrlen")
531 if exists("g:Align_xstrlen")
532 let g:netrw_xstrlen= g:Align_xstrlen
533 elseif exists("g:drawit_xstrlen")
534 let g:netrw_xstrlen= g:drawit_xstrlen
535 elseif &enc == "latin1" || !has("multi_byte")
536 let g:netrw_xstrlen= 0
537 else
538 let g:netrw_xstrlen= 1
539 endif
540endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200542call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100543call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200544if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000545" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000546" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100547call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200548if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200549 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200550else
Bram Moolenaarff034192013-04-24 18:51:19 +0200551 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200552endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200553call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100554call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
555call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100556if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100557 let s:treedepthstring= "│ "
558else
559 let s:treedepthstring= "| "
560endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200561call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000562
563" BufEnter event ignored by decho when following variable is true
564" Has a side effect that doau BufReadPost doesn't work, so
565" files read by network transfer aren't appropriately highlighted.
566"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567
Bram Moolenaaradc21822011-04-01 18:03:16 +0200568" ======================
569" Netrw Initialization: {{{1
570" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200571if 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 +0100572" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100573 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200574" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100575 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100576 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
577 au VimEnter * let s:initbeval= &beval
578"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100579" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
580" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
581" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
582" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
583" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
584" 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 +0200585endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200586au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200587
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200588if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100589 com! -nargs=* NetrwKeepj keepj <args>
590else
591 let g:netrw_keepj= ""
592 com! -nargs=* NetrwKeepj <args>
593endif
594
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000595" ==============================
596" Netrw Utility Functions: {{{1
597" ==============================
598
Bram Moolenaaradc21822011-04-01 18:03:16 +0200599" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100600" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100601if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100602" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100603 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100604 if &ft != "netrw"
605 return ""
606 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200607 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
608 " popup error window is still showing
609 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
610 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
611 " text under mouse hasn't changed; only close window when it changes
612 call popup_close(s:popuperr_id)
613 unlet s:popuperr_text
614 else
615 let s:popuperr_text= v:beval_text
616 endif
617 let mesg= ""
618 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 +0100619 let mesg= ""
620 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
621 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
622 elseif getline(v:beval_lnum) =~ '^"\s*/'
623 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
624 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100625 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100626 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
627 let mesg = "S: edit sorting sequence"
628 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
629 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
630 elseif v:beval_text == "Quick" || v:beval_text == "Help"
631 let mesg = "Help: press <F1>"
632 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
633 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
634 else
635 let mesg= ""
636 endif
637 return mesg
638 endfun
639"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100640" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
641" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
642" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
643" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
644" 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 +0200645endif
646
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200648" netrw#Explore: launch the local browser in the directory of the current file {{{2
649" indx: == -1: Nexplore
650" == -2: Pexplore
651" == +: this is overloaded:
652" * If Nexplore/Pexplore is in use, then this refers to the
653" indx'th item in the w:netrw_explore_list[] of items which
654" matched the */pattern **/pattern *//pattern **//pattern
655" * If Hexplore or Vexplore, then this will override
656" g:netrw_winsize to specify the qty of rows or columns the
657" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100658" 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 +0200659" dosplit==1: the window will be split before running the local browser
660" style == 0: Explore style == 1: Explore!
661" == 2: Hexplore style == 3: Hexplore!
662" == 4: Vexplore style == 5: Vexplore!
663" == 6: Texplore
664fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100665" 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 +0100666" 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 +0200667 if !exists("b:netrw_curdir")
668 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100669" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200670 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100671
672 " record current file for Rexplore's benefit
673 if &ft != "netrw"
674 let w:netrw_rexfile= expand("%:p")
675 endif
676
677 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200678 let curdir = simplify(b:netrw_curdir)
679 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200680 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200681 let curdir= substitute(curdir,'\','/','g')
682 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100683" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100684
685 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
686 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
687 " try Explore again.
688 if a:0 > 0
689" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100690 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
691 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
692 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
693 \ '~'.expand("<slnum>"))
694 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
695" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100696 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
697" call Dret("netrw#Explore : returning from retry")
698 return
699" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100700" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100701 endif
702 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200703
704 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200705 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100706" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100707 sil! let keepregstar = @*
708 sil! let keepregplus = @+
709 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200710 sil! let keepregslash= @/
711
Bram Moolenaar8d043172014-01-23 14:24:41 +0100712 " if dosplit
713 " -or- file has been modified AND file not hidden when abandoned
714 " -or- Texplore used
715 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100716" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200717 call s:SaveWinVars()
718 let winsz= g:netrw_winsize
719 if a:indx > 0
720 let winsz= a:indx
721 endif
722
723 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100724" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200726 if winsz == 0|let winsz= ""|endif
727 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100728" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200729
730 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100731" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200733 if winsz == 0|let winsz= ""|endif
734 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736
737 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100738" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200739 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200740 if winsz == 0|let winsz= ""|endif
741 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200743
744 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200747 if winsz == 0|let winsz= ""|endif
748 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100749" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100752" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200754 if winsz == 0|let winsz= ""|endif
755 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100756" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200757
758 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200761 if winsz == 0|let winsz= ""|endif
762 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100763" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200764
765 elseif a:style == 6 " Texplore
766 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100767" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100769" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 call s:RestoreBufVars()
771 endif
772 call s:RestoreWinVars()
773" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100776 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200777
778 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
787 if dirname !~ '/$'
788 let dirname= dirname."/"
789 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200795 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 let dirname= a:1
802 endif
803 else
804 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 call s:NetrwClearExplore()
807" call Dret("netrw#Explore : cleared list")
808 return
809 endif
810
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100811" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 if dirname =~ '\.\./\=$'
813 let dirname= simplify(fnamemodify(dirname,':p:h'))
814 elseif dirname =~ '\.\.' || dirname == '.'
815 let dirname= simplify(fnamemodify(dirname,':p'))
816 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100817" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200818
819 if dirname =~ '^\*//'
820 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
823 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
826
827 elseif dirname =~ '^\*\*//'
828 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 let pattern= substitute(dirname,'^\*\*//','','')
831 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833
834 elseif dirname =~ '/\*\*/'
835 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100836" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200838 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let b:netrw_curdir = prefixdir
840 else
841 let b:netrw_curdir= getcwd().'/'.prefixdir
842 endif
843 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
844 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
846" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200847
848 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200849 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200850 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100851" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852
853 elseif dirname=~ '^\*\*/'
854 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
855 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857
858 else
859 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200861 endif
862
863 if starpat == 0 && a:indx >= 0
864 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" 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 +0200866 if dirname == ""
867 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200870 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200871 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 if dirname == ""
874 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200875 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100876 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100877 " depending on whether backslashes have been converted to forward slashes by earlier code).
878 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200879 let dirname= b:netrw_curdir."/".dirname
880 endif
881 elseif dirname !~ '^/'
882 let dirname= b:netrw_curdir."/".dirname
883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200885 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100886" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
887" 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 +0200888 endif
889 if exists("w:netrw_bannercnt")
890 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
891 " If one wants to return the same place in the netrw window, use :Rex instead.
892 exe w:netrw_bannercnt
893 endif
894
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100895" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200896 " ---------------------------------------------------------------------
897 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
898" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100899" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200900" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100901" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200902" endif
903 " ---------------------------------------------------------------------
904
905 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
906 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
907 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
908 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
909 elseif a:indx <= 0
910 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100911" 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 +0200912 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200914 let s:didstarstar= 1
915 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
916 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
917 endif
918
919 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100920" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200921 if !exists("w:netrw_explore_indx")
922 let w:netrw_explore_indx= 0
923 endif
924
925 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100926" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200927
928 if indx == -1
929 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100930" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200931 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100932 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 +0200933 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100934" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100935 if @* != keepregstar | sil! let @* = keepregstar | endif
936 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100937 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200938 sil! let @/ = keepregslash
939" call Dret("netrw#Explore")
940 return
941 endif
942 let indx= w:netrw_explore_indx
943 if indx < 0 | let indx= 0 | endif
944 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
945 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100946" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
948 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 endwhile
951 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953
954 elseif indx == -2
955 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100956" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200957 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100958 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 +0200959 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100960" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100961 if @* != keepregstar | sil! let @* = keepregstar | endif
962 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100963 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200964 sil! let @/ = keepregslash
965" call Dret("netrw#Explore")
966 return
967 endif
968 let indx= w:netrw_explore_indx
969 if indx < 0 | let indx= 0 | endif
970 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
971 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 while indx >= 0 && curfile == w:netrw_explore_list[indx]
974 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 endwhile
977 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979
980 else
981 " Explore -- initialize
982 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100984 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 let w:netrw_explore_indx= 0
986 if !exists("b:netrw_curdir")
987 let b:netrw_curdir= getcwd()
988 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100989" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200990
991 " switch on starpat to build the w:netrw_explore_list of files
992 if starpat == 1
993 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100994" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
995" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100997 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 catch /^Vim\%((\a\+)\)\=:E480/
999 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1000" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1001 return
1002 endtry
1003 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1004 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1005
1006 elseif starpat == 2
1007 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001008" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1009" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001011 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 catch /^Vim\%((\a\+)\)\=:E480/
1013 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1014 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001015 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001016" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001017 if @* != keepregstar | sil! let @* = keepregstar | endif
1018 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001019 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001020 sil! let @/ = keepregslash
1021" call Dret("netrw#Explore : no files matched pattern")
1022 return
1023 endtry
1024 let s:netrw_curdir = b:netrw_curdir
1025 let w:netrw_explore_list = getqflist()
1026 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1027 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1028
1029 elseif starpat == 3
1030 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001031" 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 +02001032 let filepat= substitute(dirname,'^\*/','','')
1033 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001034" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1035" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001036 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1037 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1038
1039 elseif starpat == 4
1040 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001041" 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 +02001042 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1043 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1044 endif " switch on starpat to build w:netrw_explore_list
1045
1046 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001047" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1048" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001049
1050 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001051 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001052 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001053" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001054 if @* != keepregstar | sil! let @* = keepregstar | endif
1055 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001056 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001057 sil! let @/ = keepregslash
1058" call Dret("netrw#Explore : no files matched")
1059 return
1060 endif
1061 endif " if indx ... endif
1062
1063 " NetrwStatusLine support - for exploring support
1064 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001065" 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 +02001066
1067 " wrap the indx around, but issue a note
1068 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001069" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1071 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001072 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 endif
1074
1075 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 call netrw#LocalBrowseCheck(newdir)
1082 if !exists("w:netrw_liststyle")
1083 let w:netrw_liststyle= g:netrw_liststyle
1084 endif
1085 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001086 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 endif
1090 let w:netrw_explore_mtchcnt = indx + 1
1091 let w:netrw_explore_bufnr = bufnr("%")
1092 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001094" 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 +02001095
1096 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001097" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001098 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001099 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 +02001100 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001101 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001102" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001103 if @* != keepregstar | sil! let @* = keepregstar | endif
1104 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001105 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 sil! let @/ = keepregslash
1107" call Dret("netrw#Explore : missing +path_extra")
1108 return
1109 endif
1110
1111 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001112" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001113 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1114 sil! unlet w:netrw_treedict
1115 sil! unlet w:netrw_treetop
1116 endif
1117 let newdir= dirname
1118 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001119 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 endif
1123 endif
1124
1125 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001126" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1127" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001131 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001132" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 let s:explore_prvdir = b:netrw_curdir
1134 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001135 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 if b:netrw_curdir !~ '/$'
1137 let dirlen= dirlen + 1
1138 endif
1139 let prvfname= ""
1140 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001141" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001142 if fname =~ '^'.b:netrw_curdir
1143 if s:explore_match == ""
1144 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1145 else
1146 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1147 endif
1148 elseif fname !~ '^/' && fname != prvfname
1149 if s:explore_match == ""
1150 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1151 else
1152 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1153 endif
1154 endif
1155 let prvfname= fname
1156 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001157" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001158 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1159 exe "2match netrwMarkFile /".s:explore_match."/"
1160 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001161 endif
1162 echo "<s-up>==Pexplore <s-down>==Nexplore"
1163 else
1164 2match none
1165 if exists("s:explore_match") | unlet s:explore_match | endif
1166 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001167" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001168 endif
1169
Bram Moolenaara6878372014-03-22 21:02:50 +01001170 " since Explore may be used to initialize netrw's browser,
1171 " there's no danger of a late FocusGained event on initialization.
1172 " Consequently, set s:netrw_events to 2.
1173 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001174 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001175" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001176 if @* != keepregstar | sil! let @* = keepregstar | endif
1177 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001178 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001179 sil! let @/ = keepregslash
1180" call Dret("netrw#Explore : @/<".@/.">")
1181endfun
1182
1183" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001184" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001185" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1186" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1187" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1188" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1189" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001191" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192 let curwin= winnr()
1193
Bram Moolenaara6878372014-03-22 21:02:50 +01001194 if a:0 > 0 && a:1 != ""
1195 " if a netrw window is already on the left-side of the tab
1196 " and a directory has been specified, explore with that
1197 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001198" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001200" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001201 exe "1wincmd w"
1202 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001203" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 exe "Explore ".fnameescape(a1)
1205 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001206 let s:lexplore_win= curwin
1207 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001209" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 unlet t:netrw_lexposn
1211 endif
1212" call Dret("netrw#Lexplore")
1213 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001214 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 exe curwin."wincmd w"
1216 else
1217 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001218" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001219 endif
1220
Bram Moolenaar8d043172014-01-23 14:24:41 +01001221 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001223 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001224" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 else
1226 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230
1231 if lexwinnr > 0
1232 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001233" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001234 exe lexwinnr."wincmd w"
1235 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001236 let t:netrw_lexposn = winsaveview()
1237" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001238" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 close
1240 if lexwinnr < curwin
1241 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001242 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001243 if lexwinnr != curwin
1244 exe curwin."wincmd w"
1245 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001247" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248
1249 else
1250 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001251" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001252 exe "1wincmd w"
1253 let keep_altv = g:netrw_altv
1254 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 if a:count != 0
1256 let netrw_winsize = g:netrw_winsize
1257 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001258 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 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 +02001262" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001265 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267 elseif curfile =~ '^\a\{3,}://'
1268" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001269 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001271" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001272 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273 endif
1274 if a:count != 0
1275 let g:netrw_winsize = netrw_winsize
1276 endif
1277 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001278 let g:netrw_altv = keep_altv
1279 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001280 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1281 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001282 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001283 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001284" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1285" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001286 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001287" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001288" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1289 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290 unlet t:netrw_lexposn
1291 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001292 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293
1294 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001295 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001296 if a:rightside
1297 let g:netrw_chgwin= 1
1298 else
1299 let g:netrw_chgwin= 2
1300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001301" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001302 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001303
Bram Moolenaar8d043172014-01-23 14:24:41 +01001304" call Dret("netrw#Lexplore")
1305endfun
1306
1307" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001308" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001309" supports :NetrwClean -- remove netrw from first directory on runtimepath
1310" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001311fun! netrw#Clean(sys)
1312" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001313
1314 if a:sys
1315 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1316 else
1317 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001319" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001320 let diddel= 0
1321 let diddir= ""
1322
1323 if choice == 1
1324 for dir in split(&rtp,',')
1325 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001327 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1328 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1329 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1330 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1331 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1332 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 +00001333 let diddir= dir
1334 let diddel= diddel + 1
1335 if !a:sys|break|endif
1336 endif
1337 endfor
1338 endif
1339
1340 echohl WarningMsg
1341 if diddel == 0
1342 echomsg "netrw is either not installed or not removable"
1343 elseif diddel == 1
1344 echomsg "removed one copy of netrw from <".diddir.">"
1345 else
1346 echomsg "removed ".diddel." copies of netrw"
1347 endif
1348 echohl None
1349
Bram Moolenaara6878372014-03-22 21:02:50 +01001350" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001351endfun
1352
Bram Moolenaar5c736222010-01-06 20:54:52 +01001353" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001354" netrw#MakeTgt: make a target out of the directory name provided {{{2
1355fun! netrw#MakeTgt(dname)
1356" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1357 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001358 let svpos = winsaveview()
1359" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001360 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1361" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001362 if s:netrwmftgt_islocal
1363 let netrwmftgt= simplify(a:dname)
1364 else
1365 let netrwmftgt= a:dname
1366 endif
1367 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1368 " re-selected target, so just clear it
1369 unlet s:netrwmftgt s:netrwmftgt_islocal
1370 else
1371 let s:netrwmftgt= netrwmftgt
1372 endif
1373 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001374 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001375 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001376" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1377 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001378" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001379endfun
1380
Bram Moolenaara6878372014-03-22 21:02:50 +01001381" ---------------------------------------------------------------------
1382" netrw#Obtain: {{{2
1383" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001384" islocal=0 obtain from remote source
1385" =1 obtain from local source
1386" fname : a filename or a list of filenames
1387" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001388fun! netrw#Obtain(islocal,fname,...)
1389" 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 +02001390 " NetrwStatusLine support - for obtaining support
1391
1392 if type(a:fname) == 1
1393 let fnamelist= [ a:fname ]
1394 elseif type(a:fname) == 3
1395 let fnamelist= a:fname
1396 else
1397 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 +01001398" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 return
1400 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001401" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001402 if a:0 > 0
1403 let tgtdir= a:1
1404 else
1405 let tgtdir= getcwd()
1406 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408
1409 if exists("b:netrw_islocal") && b:netrw_islocal
1410 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1413 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001414 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001419 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 if v:shell_error != 0
1421 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 +01001422" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 return
1424 endif
1425 endfor
1426 else
1427 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001428" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1429 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1430" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001431 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 if v:shell_error != 0
1433 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 +01001434" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 return
1436 endif
1437 endif
1438 elseif !exists("b:netrw_curdir")
1439 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1440 else
1441 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1442 endif
1443
1444 else
1445 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001447 if type(a:fname) == 1
1448 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1449 endif
1450 call s:NetrwMethod(b:netrw_curdir)
1451
1452 if b:netrw_method == 4
1453 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001454" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001455 if exists("g:netrw_port") && g:netrw_port != ""
1456 let useport= " ".g:netrw_scpport." ".g:netrw_port
1457 else
1458 let useport= ""
1459 endif
1460 if b:netrw_fname =~ '/'
1461 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1462 else
1463 let path= ""
1464 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001465 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466 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 +02001467
1468 elseif b:netrw_method == 2
1469 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001471 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 let tmpbufnr= bufnr("%")
1473 setl ff=unix
1474 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001475 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001476" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001477 endif
1478
1479 if exists("b:netrw_fname") && b:netrw_fname != ""
1480 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001481" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001482 endif
1483
1484 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001485 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endif
1488 for fname in fnamelist
1489 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 endfor
1492 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endif
1497 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1498 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1499 let debugkeep= &debug
1500 setl debug=msg
1501 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1502 let &debug= debugkeep
1503 endif
1504
1505 elseif b:netrw_method == 3
1506 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001507" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001508 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001509 let tmpbufnr= bufnr("%")
1510 setl ff=unix
1511
1512 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
1519
1520 if exists("g:netrw_uid") && g:netrw_uid != ""
1521 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001529 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
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 endif
1533
1534 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001535 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001536" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001537 endif
1538
1539 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001541" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001542 endif
1543
1544 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001546" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001547 endif
1548
1549 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001550 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001551" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endif
1553 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001554 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001555 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001557
1558 " perform ftp:
1559 " -i : turns off interactive prompting from ftp
1560 " -n unix : DON'T use <.netrc>, even though it exists
1561 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001562 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1563 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001564 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001565 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1566 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001567" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001569 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 endif
1571 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001572
1573 elseif b:netrw_method == 9
1574 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001575" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001576 if a:fname =~ '/'
1577 let localfile= substitute(a:fname,'^.*/','','')
1578 else
1579 let localfile= a:fname
1580 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001581 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 +02001582
Bram Moolenaarff034192013-04-24 18:51:19 +02001583 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001584 " probably a badly formed url; protocol not recognized
1585" call Dret("netrw#Obtain : unsupported method")
1586 return
1587
1588 else
1589 " protocol recognized but not supported for Obtain (yet?)
1590 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001591 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001592 endif
1593" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001594 return
1595 endif
1596
1597 " restore status line
1598 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001599 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001600 endif
1601
1602 endif
1603
1604 " cleanup
1605 if exists("tmpbufnr")
1606 if bufnr("%") != tmpbufnr
1607 exe tmpbufnr."bw!"
1608 else
1609 q!
1610 endif
1611 endif
1612
Bram Moolenaara6878372014-03-22 21:02:50 +01001613" call Dret("netrw#Obtain")
1614endfun
1615
1616" ---------------------------------------------------------------------
1617" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1618fun! netrw#Nread(mode,fname)
1619" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001620 let svpos= winsaveview()
1621" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001622 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001623" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1624 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001625
1626 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1627 if exists("w:netrw_bannercnt")
1628 " start with cursor just after the banner
1629 exe w:netrw_bannercnt
1630 endif
1631 endif
1632" call Dret("netrw#Nread")
1633endfun
1634
1635" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001636" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1637" Options get restored by s:NetrwOptionsRestore()
1638"
1639" Option handling:
1640" * save user's options (s:NetrwOptionsSave)
1641" * set netrw-safe options (s:NetrwOptionsSafe)
1642" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1643" * restore user's options (s:netrwOPtionsRestore)
1644" - restore a user option when != safe option (s:NetrwRestoreSetting)
1645" vt: (variable type) normally its either "w:" or "s:"
1646fun! s:NetrwOptionsSave(vt)
1647" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1648" 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 +02001649" 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>"))
1650" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001651
1652 if !exists("{a:vt}netrw_optionsave")
1653 let {a:vt}netrw_optionsave= 1
1654 else
1655" call Dret("s:NetrwOptionsSave : options already saved")
1656 return
1657 endif
1658" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1659
1660 " Save current settings and current directory
1661" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1662 let s:yykeep = @@
1663 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1664 let {a:vt}netrw_aikeep = &l:ai
1665 let {a:vt}netrw_awkeep = &l:aw
1666 let {a:vt}netrw_bhkeep = &l:bh
1667 let {a:vt}netrw_blkeep = &l:bl
1668 let {a:vt}netrw_btkeep = &l:bt
1669 let {a:vt}netrw_bombkeep = &l:bomb
1670 let {a:vt}netrw_cedit = &cedit
1671 let {a:vt}netrw_cikeep = &l:ci
1672 let {a:vt}netrw_cinkeep = &l:cin
1673 let {a:vt}netrw_cinokeep = &l:cino
1674 let {a:vt}netrw_comkeep = &l:com
1675 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001676 let {a:vt}netrw_cuckeep = &l:cuc
1677 let {a:vt}netrw_culkeep = &l:cul
1678" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 let {a:vt}netrw_diffkeep = &l:diff
1680 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001681 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1682 let {a:vt}netrw_ffkeep = &l:ff
1683 endif
1684 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1685 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001686 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001687 let {a:vt}netrw_hidkeep = &l:hidden
1688 let {a:vt}netrw_imkeep = &l:im
1689 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001690 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001691 let {a:vt}netrw_lskeep = &l:ls
1692 let {a:vt}netrw_makeep = &l:ma
1693 let {a:vt}netrw_magickeep = &l:magic
1694 let {a:vt}netrw_modkeep = &l:mod
1695 let {a:vt}netrw_nukeep = &l:nu
1696 let {a:vt}netrw_rnukeep = &l:rnu
1697 let {a:vt}netrw_repkeep = &l:report
1698 let {a:vt}netrw_rokeep = &l:ro
1699 let {a:vt}netrw_selkeep = &l:sel
1700 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001701 if !g:netrw_use_noswf
1702 let {a:vt}netrw_swfkeep = &l:swf
1703 endif
1704 let {a:vt}netrw_tskeep = &l:ts
1705 let {a:vt}netrw_twkeep = &l:tw " textwidth
1706 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1707 let {a:vt}netrw_wrapkeep = &l:wrap
1708 let {a:vt}netrw_writekeep = &l:write
1709
1710 " save a few selected netrw-related variables
1711" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1712 if g:netrw_keepdir
1713 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001714" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001715 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001716 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001717 sil! let {a:vt}netrw_starkeep = @*
1718 sil! let {a:vt}netrw_pluskeep = @+
1719 endif
1720 sil! let {a:vt}netrw_slashkeep= @/
1721
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001722" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001723" 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>"))
1724" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1725endfun
1726
1727" ---------------------------------------------------------------------
1728" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1729" Use s:NetrwSaveOptions() to save user settings
1730" Use s:NetrwOptionsRestore() to restore user settings
1731fun! s:NetrwOptionsSafe(islocal)
1732" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1733" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1734" 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>"))
1735 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1736 call s:NetrwSetSafeSetting("&l:ai",0)
1737 call s:NetrwSetSafeSetting("&l:aw",0)
1738 call s:NetrwSetSafeSetting("&l:bl",0)
1739 call s:NetrwSetSafeSetting("&l:bomb",0)
1740 if a:islocal
1741 call s:NetrwSetSafeSetting("&l:bt","nofile")
1742 else
1743 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1744 endif
1745 call s:NetrwSetSafeSetting("&l:ci",0)
1746 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001747 if g:netrw_fastbrowse > a:islocal
1748 call s:NetrwSetSafeSetting("&l:bh","hide")
1749 else
1750 call s:NetrwSetSafeSetting("&l:bh","delete")
1751 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001752 call s:NetrwSetSafeSetting("&l:cino","")
1753 call s:NetrwSetSafeSetting("&l:com","")
1754 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1755 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1756 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001757 if &go =~ 'a' | set go-=a | endif
1758 if &go =~ 'A' | set go-=A | endif
1759 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001760 call s:NetrwSetSafeSetting("&l:hid",0)
1761 call s:NetrwSetSafeSetting("&l:im",0)
1762 setl isk+=@ isk+=* isk+=/
1763 call s:NetrwSetSafeSetting("&l:magic",1)
1764 if g:netrw_use_noswf
1765 call s:NetrwSetSafeSetting("swf",0)
1766 endif
1767 call s:NetrwSetSafeSetting("&l:report",10000)
1768 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1769 call s:NetrwSetSafeSetting("&l:spell",0)
1770 call s:NetrwSetSafeSetting("&l:tw",0)
1771 call s:NetrwSetSafeSetting("&l:wig","")
1772 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001773
1774 " set up cuc and cul based on g:netrw_cursor and listing style
1775 " COMBAK -- cuc cul related
1776 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001777
1778 " allow the user to override safe options
1779" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1780 if &ft == "netrw"
1781" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1782 keepalt NetrwKeepj doau FileType netrw
1783 endif
1784
1785" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1786" 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>"))
1787" call Dret("s:NetrwOptionsSafe")
1788endfun
1789
1790" ---------------------------------------------------------------------
1791" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1792fun! s:NetrwOptionsRestore(vt)
1793" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001794" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001795" 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 +01001796 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001797" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001798
1799 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1800 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001801" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001802 filetype detect
1803" 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>"))
1804 else
1805 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001806 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001807" 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 +02001808" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001809 return
1810 endif
1811 unlet {a:vt}netrw_optionsave
1812
1813 if exists("+acd")
1814 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001815" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001816 let curdir = getcwd()
1817 let &l:acd = {a:vt}netrw_acdkeep
1818 unlet {a:vt}netrw_acdkeep
1819 if &l:acd
1820 call s:NetrwLcd(curdir)
1821 endif
1822 endif
1823 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001824" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001825 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1826 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1827 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1828 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1829 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001830" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001831 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1832 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1833 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1835 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001836" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001837 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1838 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1839 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1840 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1841 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001842 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001843" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1844 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1845 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001846 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001847 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1848" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1850 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1851" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1853" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1855 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001856 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001857 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1858 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1859" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1860 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1861 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1862 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1863 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1864" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001865 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1867 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1868 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001869 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001870" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 call s:NetrwRestoreSetting("s:yykeep","@@")
1872 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1873 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1874 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1875 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1876
Bram Moolenaara6878372014-03-22 21:02:50 +01001877 if exists("{a:vt}netrw_swfkeep")
1878 if &directory == ""
1879 " user hasn't specified a swapfile directory;
1880 " netrw will temporarily set the swapfile directory
1881 " to the current directory as returned by getcwd().
1882 let &l:directory= getcwd()
1883 sil! let &l:swf = {a:vt}netrw_swfkeep
1884 setl directory=
1885 unlet {a:vt}netrw_swfkeep
1886 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001887 if !g:netrw_use_noswf
1888 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1889 sil! let &l:swf= {a:vt}netrw_swfkeep
1890 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001891 unlet {a:vt}netrw_swfkeep
1892 endif
1893 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001894 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001895 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1896 if exists("{a:vt}netrw_dirkeep")
1897 call s:NetrwLcd(dirkeep)
1898 unlet {a:vt}netrw_dirkeep
1899 endif
1900 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001901 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001902" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001903 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1904 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001905 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001906 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001907
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001908" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1909" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1910" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1911" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1912" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001913 " Moved the filetype detect here from NetrwGetFile() because remote files
1914 " were having their filetype detect-generated settings overwritten by
1915 " NetrwOptionRestore.
1916 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001917" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1918 filetype detect
1919" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001920 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001921" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001922" 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 +02001923" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001924endfun
1925
1926" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001927" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1928" but only when the options' value and the safe setting differ
1929" Doing this means that netrw will not come up as having changed a
1930" setting last when it really didn't actually change it.
1931"
1932" Called from s:NetrwOptionsSafe
1933" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1934fun! s:NetrwSetSafeSetting(setting,safesetting)
1935" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001936
Bram Moolenaar85850f32019-07-19 22:05:51 +02001937 if a:setting =~ '^&'
1938" call Decho("fyi: a:setting starts with &")
1939 exe "let settingval= ".a:setting
1940" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001941
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942 if settingval != a:safesetting
1943" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1944 if type(a:safesetting) == 0
1945 exe "let ".a:setting."=".a:safesetting
1946 elseif type(a:safesetting) == 1
1947 exe "let ".a:setting."= '".a:safesetting."'"
1948 else
1949 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1950 endif
1951 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001952 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001953
Bram Moolenaar85850f32019-07-19 22:05:51 +02001954" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001955endfun
1956
1957" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001958" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1959" but only if the setting value differs from the associated keepvar.
1960" Doing this means that netrw will not come up as having changed a
1961" setting last when it really didn't actually change it.
1962"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001963" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964" keepvars are set up by s:NetrwOptionsSave
1965fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001966""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001967
Bram Moolenaar85850f32019-07-19 22:05:51 +02001968 " typically called from s:NetrwOptionsRestore
1969 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1970 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001971 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001972 if exists(a:keepvar)
1973 exe "let keepvarval= ".a:keepvar
1974 exe "let setting= ".a:setting
1975
1976"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1977"" call Decho("fyi: keepvarval=".keepvarval)
1978"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1979
1980 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001981"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001982 if type(a:setting) == 0
1983 exe "let ".a:setting."= ".keepvarval
1984 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001985 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001986 else
1987 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1988 endif
1989 endif
1990
1991 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001992 endif
1993
Bram Moolenaar85850f32019-07-19 22:05:51 +02001994"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001995endfun
1996
1997" ---------------------------------------------------------------------
1998" NetrwStatusLine: {{{2
1999fun! NetrwStatusLine()
2000
2001" vvv NetrwStatusLine() debugging vvv
2002" let g:stlmsg=""
2003" if !exists("w:netrw_explore_bufnr")
2004" let g:stlmsg="!X<explore_bufnr>"
2005" elseif w:netrw_explore_bufnr != bufnr("%")
2006" let g:stlmsg="explore_bufnr!=".bufnr("%")
2007" endif
2008" if !exists("w:netrw_explore_line")
2009" let g:stlmsg=" !X<explore_line>"
2010" elseif w:netrw_explore_line != line(".")
2011" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2012" endif
2013" if !exists("w:netrw_explore_list")
2014" let g:stlmsg=" !X<explore_list>"
2015" endif
2016" ^^^ NetrwStatusLine() debugging ^^^
2017
2018 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")
2019 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002020 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002021 let &laststatus = s:netrw_users_ls
2022 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2023 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2024 return ""
2025 else
2026 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2027 endif
2028endfun
2029
Bram Moolenaar85850f32019-07-19 22:05:51 +02002030" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002031" Netrw Transfer Functions: {{{1
2032" ===============================
2033
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002035" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002036" mode: =0 read remote file and insert before current line
2037" =1 read remote file and insert after current line
2038" =2 replace with remote file
2039" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002040fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002041" 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 +00002042
Bram Moolenaar5c736222010-01-06 20:54:52 +01002043 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002044 call s:NetrwOptionsSave("w:")
2045 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002046 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002047 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2048 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2049 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002050" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051
Bram Moolenaar5c736222010-01-06 20:54:52 +01002052 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 elseif a:mode == 2 " replace with remote file
2058 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002059 elseif a:mode == 3 " skip read of file (leave as temporary)
2060 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061 else
2062 exe a:mode
2063 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002066" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067
Bram Moolenaar5c736222010-01-06 20:54:52 +01002068 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002069 let tmpfile= s:GetTempfile("")
2070 if tmpfile == ""
2071" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002072 return
2073 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 " attempt to repeat with previous host-file-etc
2078 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 let choice = b:netrw_lastfile
2081 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 else
2084 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002085" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002086
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002087 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002088 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002089 echomsg 'NetRead Usage:'
2090 echomsg ':Nread machine:path uses rcp'
2091 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2092 echomsg ':Nread "machine id password path" uses ftp'
2093 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2094 echomsg ':Nread fetch://machine/path uses fetch'
2095 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2096 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002097 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002098 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002099 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2100 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2101 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2102 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002105
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002107 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002108" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002109 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002111 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 else
2113 " case "... ... ..."
2114 let choice = strpart(choice,1,strlen(choice)-1)
2115 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002116
Bram Moolenaar9964e462007-05-05 17:54:07 +00002117 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002118 let wholechoice = wholechoice . " " . choice
2119 let ichoice = ichoice + 1
2120 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002121 if !exists("g:netrw_quiet")
2122 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2123 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002124" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 return
2126 endif
2127 let choice= a:{ichoice}
2128 endwhile
2129 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2130 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 endif
2132 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002134" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002135 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002136
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002138 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002140" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002141 return
2142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002143 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002144
Bram Moolenaar8d043172014-01-23 14:24:41 +01002145 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146" 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 +02002147 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002149 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002150" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002153
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002155 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002156 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002157 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2158 echo "(netrw) Processing your read request..."
2159 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002160
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002162 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002164" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002165 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002167 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 " ER: the tmpfile is full path: rcp sees C:\... as host C
2169 if s:netrw_has_nt_rcp == 1
2170 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2171 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2172 else
2173 " Any way needed it machine contains a '.'
2174 let uid_machine = g:netrw_machine .'.'. $USERNAME
2175 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2178 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2179 else
2180 let uid_machine = g:netrw_machine
2181 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002183 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 +00002184 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002186
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002188 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002190" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002191 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002193 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002194 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002197 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002201 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 endif
2208 " 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 +00002209 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002210 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002211 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002212 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002213 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002215 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002216 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002217 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2218 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002219 q!
2220 endif
2221 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002222 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002226 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2228 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002229" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002231 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002232 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002233 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002235 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002236" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002238 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002241
Bram Moolenaar97d62492012-11-15 21:28:22 +01002242 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002260 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002261 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002264 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002266
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 " perform ftp:
2268 " -i : turns off interactive prompting from ftp
2269 " -n unix : DON'T use <.netrc>, even though it exists
2270 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002271 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002272 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2274 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002275" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002276 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002277 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002281 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002283
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002285 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002287" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002289 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 else
2291 let useport= ""
2292 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002293 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2294 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002295 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002296 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2297 else
2298 let tmpfile_get = tmpfile
2299 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002300 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 +00002301 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002303
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002305 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002306 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002307" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002309 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002310 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002311 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002312" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002313 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002314 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002316 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2317 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002319 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320 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 +00002321 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322 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 +00002323 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002324 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002325
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002327 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002329 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2330 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2332" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2333 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 +00002334 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002336 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002337 endif
2338 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002339" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002340 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002341
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002342 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002343 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002344 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002345" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaar5c736222010-01-06 20:54:52 +01002347 if !executable(g:netrw_dav_cmd)
2348 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2349" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2350 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002351 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002353 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 +01002354 else
2355 " Construct execution string (four lines) which will be passed through filter
2356 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2357 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002358 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002364 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002366 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2368 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002369
Bram Moolenaar5c736222010-01-06 20:54:52 +01002370 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002371 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002373 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002374 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002375 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002377
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002380 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002381" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002382 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 +00002383 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002385
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002387 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002389 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002390" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002392 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002393 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002394 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002395" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002396 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002398 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 let netrw_option= "http"
2400 else
2401 let netrw_option= "ftp"
2402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002403" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaar446cb832008-06-24 21:56:24 +00002405 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002407 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408 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 +00002409 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaar446cb832008-06-24 21:56:24 +00002411 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002414 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002417 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002418 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002419" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2420 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 +00002421 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002422 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002423
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002424 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002425 " NetRead: (file) NetRead Method #10 {{{3
2426 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002427" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2428 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002429 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2430 let b:netrw_lastfile = choice
2431
2432 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002433 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002434 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002435 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 endif
2437 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002438
Bram Moolenaar5c736222010-01-06 20:54:52 +01002439 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002441" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 unlet b:netrw_fname
2444 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002445 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 +01002446" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002447 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002448 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002449 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002450
Bram Moolenaar9964e462007-05-05 17:54:07 +00002451" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452endfun
2453
2454" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002455" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002456fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002457" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002458
Bram Moolenaar5c736222010-01-06 20:54:52 +01002459 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002460 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002461 call s:NetrwOptionsSave("w:")
2462 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002463
Bram Moolenaar5c736222010-01-06 20:54:52 +01002464 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002465 let tmpfile= s:GetTempfile("")
2466 if tmpfile == ""
2467" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002468 return
2469 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002470
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002471 if a:0 == 0
2472 let ichoice = 0
2473 else
2474 let ichoice = 1
2475 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002476
Bram Moolenaar9964e462007-05-05 17:54:07 +00002477 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002478" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002479 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002480 " For binary writes, always write entire file.
2481 " (line numbers don't really make sense for that).
2482 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002484 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 elseif g:netrw_cygwin
2486 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002487 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" 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 +01002489 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002490 else
2491 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" 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 +01002493 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002494 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002495
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002497 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 " on the temporary file's name. Deletion of the temporary file during
2499 " cleanup then causes an error message.
2500 0file!
2501 endif
2502
Bram Moolenaar5c736222010-01-06 20:54:52 +01002503 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002505
Bram Moolenaar9964e462007-05-05 17:54:07 +00002506 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 " attempt to repeat with previous host-file-etc
2508 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002509" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 let choice = b:netrw_lastfile
2511 let ichoice= ichoice + 1
2512 else
2513 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002514
Bram Moolenaar8d043172014-01-23 14:24:41 +01002515 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002516 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002517 echomsg 'NetWrite Usage:"'
2518 echomsg ':Nwrite machine:path uses rcp'
2519 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2520 echomsg ':Nwrite "machine id password path" uses ftp'
2521 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2522 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2523 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2524 echomsg ':Nwrite rcp://machine/path uses rcp'
2525 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2526 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2527 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002528 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002530
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002531 elseif match(choice,"^\"") != -1
2532 if match(choice,"\"$") != -1
2533 " case "..."
2534 let choice=strpart(choice,1,strlen(choice)-2)
2535 else
2536 " case "... ... ..."
2537 let choice = strpart(choice,1,strlen(choice)-1)
2538 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 while match(choice,"\"$") == -1
2541 let wholechoice= wholechoice . " " . choice
2542 let ichoice = ichoice + 1
2543 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002544 if !exists("g:netrw_quiet")
2545 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2546 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002547" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002548 return
2549 endif
2550 let choice= a:{ichoice}
2551 endwhile
2552 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2553 endif
2554 endif
2555 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002556 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002557" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002558
Bram Moolenaar9964e462007-05-05 17:54:07 +00002559 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002561 if !exists("b:netrw_method") || b:netrw_method < 0
2562" call Dfunc("netrw#NetWrite : unsupported method")
2563 return
2564 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002565
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002566 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002568 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002569 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2570 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002571" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002572 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002573
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002575 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002576 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002577" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002578 if s:netrw_has_nt_rcp == 1
2579 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2580 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2581 else
2582 let uid_machine = g:netrw_machine .'.'. $USERNAME
2583 endif
2584 else
2585 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2586 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2587 else
2588 let uid_machine = g:netrw_machine
2589 endif
2590 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002591 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 +00002592 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002593
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002595 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002596 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598 let netrw_fname = b:netrw_fname
2599
2600 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2601 let bhkeep = &l:bh
2602 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002603 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002605
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002607 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002610 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002613 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617 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 +00002618 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2620 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 endif
2622 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2623 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002624 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002625 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002626 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002629
2630 " remove enew buffer (quietly)
2631 let filtbuf= bufnr("%")
2632 exe curbuf."b!"
2633 let &l:bh = bhkeep
2634 exe filtbuf."bw!"
2635
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002637
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002638 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002640 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002642" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 let netrw_fname = b:netrw_fname
2644 let bhkeep = &l:bh
2645
2646 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2647 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002648 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002649 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002650 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002651
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002656 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 if exists("g:netrw_uid") && g:netrw_uid != ""
2660 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002668 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002671 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002677 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002680 " save choice/id/password for future use
2681 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002682
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 " perform ftp:
2684 " -i : turns off interactive prompting from ftp
2685 " -n unix : DON'T use <.netrc>, even though it exists
2686 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002687 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002688 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2690 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002691 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002692 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002693 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 let mod=1
2695 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002696
2697 " remove enew buffer (quietly)
2698 let filtbuf= bufnr("%")
2699 exe curbuf."b!"
2700 let &l:bh= bhkeep
2701 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002702
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002704 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002705 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002707 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002708 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 else
2710 let useport= ""
2711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712 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 +00002713 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002714
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002716 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002718" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002719 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2720 if executable(curl)
2721 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002722 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 +01002723 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002724 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002725 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002726
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002727 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002728 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002729 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002730" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002731
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2734 let bhkeep = &l:bh
2735
2736 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2737 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002738 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002740
Bram Moolenaarff034192013-04-24 18:51:19 +02002741 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002747 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002749 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002751
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002752 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002753 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002754 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002755
2756 " remove enew buffer (quietly)
2757 let filtbuf= bufnr("%")
2758 exe curbuf."b!"
2759 let &l:bh = bhkeep
2760 exe filtbuf."bw!"
2761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002762 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002763
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002764 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002765 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002766 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002767" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002768 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 +00002769 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002770
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002771 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002772 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002773 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002774" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002775 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2777 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2778 else
2779 let uid_machine = g:netrw_machine
2780 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781
2782 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2783 let bhkeep = &l:bh
2784 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002785 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787
Bram Moolenaarff034192013-04-24 18:51:19 +02002788 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002790" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002791 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002793 let filtbuf= bufnr("%")
2794 exe curbuf."b!"
2795 let &l:bh = bhkeep
2796 exe filtbuf."bw!"
2797 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002798
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002799 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002800 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002801 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002802 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002803 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002805 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002806
Bram Moolenaar5c736222010-01-06 20:54:52 +01002807 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002811 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002813 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002814
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002815 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002816 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002817 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" 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 +02002819 elseif !exists("leavemod")
2820 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002822 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" 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 +00002824 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002825
Bram Moolenaar9964e462007-05-05 17:54:07 +00002826" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002827endfun
2828
2829" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002830" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831" uses NetRead to get a copy of the file into a temporarily file,
2832" then sources that file,
2833" then removes that file.
2834fun! netrw#NetSource(...)
2835" call Dfunc("netrw#NetSource() a:0=".a:0)
2836 if a:0 > 0 && a:1 == '?'
2837 " give help
2838 echomsg 'NetSource Usage:'
2839 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2840 echomsg ':Nsource fetch://machine/path uses fetch'
2841 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002842 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2844 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2845 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2846 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2847 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002848 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002850 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002855 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002857 if delete(s:netrw_tmpfile)
2858 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2859 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 unlet s:netrw_tmpfile
2861 else
2862 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2863 endif
2864 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002865 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002866 endif
2867" call Dret("netrw#NetSource")
2868endfun
2869
Bram Moolenaar8d043172014-01-23 14:24:41 +01002870" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002871" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2872" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002873fun! netrw#SetTreetop(iscmd,...)
2874" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2875" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002876
Bram Moolenaar85850f32019-07-19 22:05:51 +02002877 " iscmd==0: netrw#SetTreetop called using gn mapping
2878 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2879" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002880 " clear out the current tree
2881 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002882" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002883 let inittreetop= w:netrw_treetop
2884 unlet w:netrw_treetop
2885 endif
2886 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 unlet w:netrw_treedict
2889 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002890" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002891
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002893 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002895 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896 if isdirectory(s:NetrwFile(a:1))
2897" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = a:1
2899 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002900 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002901 let treedir = b:netrw_curdir."/".a:1
2902 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002903" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002904 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 " normally the cursor is left in the message window.
2906 " However, here this results in the directory being listed in the message window, which is not wanted.
2907 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002908 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002910 let treedir = "."
2911 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002912 endif
2913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915
2916 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917 let islocal= expand("%") !~ '^\a\{3,}://'
2918" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002919
2920 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002921 if islocal
2922 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2923 else
2924 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2925 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002926
Bram Moolenaara6878372014-03-22 21:02:50 +01002927" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002928endfun
2929
Bram Moolenaar9964e462007-05-05 17:54:07 +00002930" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002931" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" readcmd == %r : replace buffer with newly read file
2933" == 0r : read file at top of buffer
2934" == r : read file after current line
2935" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936fun! s:NetrwGetFile(readcmd, tfile, method)
2937" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002938
2939 " readcmd=='t': simply do nothing
2940 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002941" 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 +01002942" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002943 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002944 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002945
Bram Moolenaar9964e462007-05-05 17:54:07 +00002946 " get name of remote filename (ie. url and all)
2947 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002948" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002949
Bram Moolenaar9964e462007-05-05 17:54:07 +00002950 if exists("*NetReadFixup")
2951 " for the use of NetReadFixup (not otherwise used internally)
2952 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002953 endif
2954
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 if a:readcmd[0] == '%'
2956 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002957" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958
2959 " rename the current buffer to the temp file (ie. tfile)
2960 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002961 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962 else
2963 let tfile= a:tfile
2964 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002965 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966
2967 " edit temporary file (ie. read the temporary file in)
2968 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 call zip#Browse(tfile)
2971 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.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\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 call tar#Browse(tfile)
2983 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002988 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989 endif
2990
2991 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002992 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002993
Bram Moolenaar71badf92023-04-22 22:40:14 +01002994 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002995 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002996 " Note that isk must not include a "/" for scripts.vim
2997 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002998" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2999" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003000" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003001" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3002 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003003 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003004 filetype detect
3005" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003006 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003007" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003008 let line1 = 1
3009 let line2 = line("$")
3010
Bram Moolenaar8d043172014-01-23 14:24:41 +01003011 elseif !&ma
3012 " 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 +01003013 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003014" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003015 return
3016
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 elseif s:FileReadable(a:tfile)
3018 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003020 let curline = line(".")
3021 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003022" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003023 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003024 let line1= curline + 1
3025 let line2= line("$") - lastline + 1
3026
3027 else
3028 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003029" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3030" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003031 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003032" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003033 return
3034 endif
3035
3036 " User-provided (ie. optional) fix-it-up command
3037 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003039 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003040" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003041" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042 endif
3043
Bram Moolenaaradc21822011-04-01 18:03:16 +02003044 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003045 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003046 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003047 endif
3048
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003049" 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 +00003050
3051 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003052" redraw!
3053
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" 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 +00003055" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003056endfun
3057
Bram Moolenaar9964e462007-05-05 17:54:07 +00003058" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003059" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003060" Input:
3061" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3062" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" b:netrw_method= 1: rcp
3064" 2: ftp + <.netrc>
3065" 3: ftp + machine, id, password, and [path]filename
3066" 4: scp
3067" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003068" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003069" 7: rsync
3070" 8: fetch
3071" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003072" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003073" g:netrw_machine= hostname
3074" b:netrw_fname = filename
3075" g:netrw_port = optional port number (for ftp)
3076" g:netrw_choice = copy of input url (choice)
3077fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003078" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003079
Bram Moolenaar251e1912011-06-19 05:09:16 +02003080 " sanity check: choice should have at least three slashes in it
3081 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3082 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3083 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003084" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003085 return
3086 endif
3087
Bram Moolenaar5c736222010-01-06 20:54:52 +01003088 " record current g:netrw_machine, if any
3089 " curmachine used if protocol == ftp and no .netrc
3090 if exists("g:netrw_machine")
3091 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003092" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003093 else
3094 let curmachine= "N O T A HOST"
3095 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003096 if exists("g:netrw_port")
3097 let netrw_port= g:netrw_port
3098 endif
3099
3100 " insure that netrw_ftp_cmd starts off every method determination
3101 " with the current g:netrw_ftp_cmd
3102 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003103
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 " initialization
3105 let b:netrw_method = 0
3106 let g:netrw_machine = ""
3107 let b:netrw_fname = ""
3108 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003109 let g:netrw_choice = a:choice
3110
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003112 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003113 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3114 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003115 " rcpurm : rcp://[user@]host/filename Use rcp
3116 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003118 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003119 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 " rsyncurm : rsync://host[:port]/path Use rsync
3121 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3122 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003123 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3125 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003126 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3127 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003129 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003130 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003131 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003133 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003135 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003136
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003139 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003141" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003142 let b:netrw_method = 1
3143 let userid = substitute(a:choice,rcpurm,'\1',"")
3144 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3145 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003146 if userid != ""
3147 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003149
Bram Moolenaaradc21822011-04-01 18:03:16 +02003150 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003152" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003153 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003154 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3155 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3156 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003157
Bram Moolenaar15146672011-10-20 22:22:38 +02003158 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003159 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003160" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 let b:netrw_method = 5
3162 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3163 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003164 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003165
Bram Moolenaaradc21822011-04-01 18:03:16 +02003166 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003168" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003170 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003171 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3172 else
3173 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3174 endif
3175 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003176
Bram Moolenaaradc21822011-04-01 18:03:16 +02003177 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003179" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 let b:netrw_method = 7
3181 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3182 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003183
Bram Moolenaaradc21822011-04-01 18:03:16 +02003184 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003186" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003187 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3189 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3190 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003191" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003192 if userid != ""
3193 let g:netrw_uid= userid
3194 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003195
Bram Moolenaaradc21822011-04-01 18:03:16 +02003196 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003197 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003198 call NetUserPass("ftp:".g:netrw_machine)
3199 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003200 " if there's a change in hostname, require password re-entry
3201 unlet s:netrw_passwd
3202 endif
3203 if exists("netrw_port")
3204 unlet netrw_port
3205 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003206 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207
Bram Moolenaar446cb832008-06-24 21:56:24 +00003208 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003209 let b:netrw_method = 3
3210 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003211 let host= substitute(g:netrw_machine,'\..*$','','')
3212 if exists("s:netrw_hup[host]")
3213 call NetUserPass("ftp:".host)
3214
Nir Lichtman1e34b952024-05-08 19:19:34 +02003215 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003216" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3217" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003218 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003219 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003220" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003221 endif
3222 let b:netrw_method= 2
3223 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003224" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003225 let b:netrw_method= 2
3226 else
3227 if !exists("g:netrw_uid") || g:netrw_uid == ""
3228 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003229 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003231 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 endif
3233 let b:netrw_method= 3
3234 endif
3235 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003236
Bram Moolenaaradc21822011-04-01 18:03:16 +02003237 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003238 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003239" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 let b:netrw_method = 8
3241 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3242 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3243 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3244 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003245
Bram Moolenaaradc21822011-04-01 18:03:16 +02003246 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003248" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3251 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003252 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003254 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003255
Bram Moolenaaradc21822011-04-01 18:03:16 +02003256 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003258" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003259 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003260 let b:netrw_method = 3
3261 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3262 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003263
Bram Moolenaar9964e462007-05-05 17:54:07 +00003264 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 let b:netrw_method = 2
3266 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3267 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3268 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003269
Bram Moolenaaradc21822011-04-01 18:03:16 +02003270 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 let b:netrw_method = 9
3274 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3275 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003276
Bram Moolenaaradc21822011-04-01 18:03:16 +02003277 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003278 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003279" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003280 let b:netrw_method = 1
3281 let userid = substitute(a:choice,rcphf,'\2',"")
3282 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3283 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003284" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3285" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3286" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3287" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003288 if userid != ""
3289 let g:netrw_uid= userid
3290 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003291
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003292 " Method#10: file://user@hostname/...path-to-file {{{3
3293 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003294" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003295 let b:netrw_method = 10
3296 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003297" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003298
Bram Moolenaaradc21822011-04-01 18:03:16 +02003299 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003300 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003301 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003302 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003303 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003304 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003306 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003307
Bram Moolenaar81695252004-12-29 20:58:21 +00003308 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003309 " remove any leading [:#] from port number
3310 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3311 elseif exists("netrw_port")
3312 " retain port number as implicit for subsequent ftp operations
3313 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003314 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003315
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003316" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3317" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3318" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3319" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003320" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003323" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003327" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329
Bram Moolenaar9964e462007-05-05 17:54:07 +00003330" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003331" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003332" Usage: :call NetUserPass() -- will prompt for userid and password
3333" :call NetUserPass("uid") -- will prompt for password
3334" :call NetUserPass("uid","password") -- sets global userid and password
3335" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3336" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337fun! NetUserPass(...)
3338
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003339" call Dfunc("NetUserPass() a:0=".a:0)
3340
3341 if !exists('s:netrw_hup')
3342 let s:netrw_hup= {}
3343 endif
3344
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003346 " case: no input arguments
3347
3348 " change host and username if not previously entered; get new password
3349 if !exists("g:netrw_machine")
3350 let g:netrw_machine= input('Enter hostname: ')
3351 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003353 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 let g:netrw_uid= input('Enter username: ')
3355 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003356 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003357 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003358
3359 " set up hup database
3360 let host = substitute(g:netrw_machine,'\..*$','','')
3361 if !exists('s:netrw_hup[host]')
3362 let s:netrw_hup[host]= {}
3363 endif
3364 let s:netrw_hup[host].uid = g:netrw_uid
3365 let s:netrw_hup[host].passwd = s:netrw_passwd
3366
3367 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003368 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003369
3370 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003371 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003372 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003373" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374 let host = substitute(a:1,'^ftp:','','')
3375 let host = substitute(host,'\..*','','')
3376 if exists("s:netrw_hup[host]")
3377 let g:netrw_uid = s:netrw_hup[host].uid
3378 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003379" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3380" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003381 else
3382 let g:netrw_uid = input("Enter UserId: ")
3383 let s:netrw_passwd = inputsecret("Enter Password: ")
3384 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003385
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003386 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003388" 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 +02003389 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003390 if g:netrw_machine =~ '[0-9.]\+'
3391 let host= g:netrw_machine
3392 else
3393 let host= substitute(g:netrw_machine,'\..*$','','')
3394 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003395 else
3396 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003397 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003398 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003399" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400 if exists("g:netrw_passwd")
3401 " ask for password if one not previously entered
3402 let s:netrw_passwd= g:netrw_passwd
3403 else
3404 let s:netrw_passwd = inputsecret("Enter Password: ")
3405 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406 endif
3407
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003408" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003409 if exists("host")
3410 if !exists('s:netrw_hup[host]')
3411 let s:netrw_hup[host]= {}
3412 endif
3413 let s:netrw_hup[host].uid = g:netrw_uid
3414 let s:netrw_hup[host].passwd = s:netrw_passwd
3415 endif
3416
3417 elseif a:0 == 2
3418 let g:netrw_uid = a:1
3419 let s:netrw_passwd = a:2
3420
3421 elseif a:0 == 3
3422 " enter hostname, user-id, and password into the hup dictionary
3423 let host = substitute(a:1,'^\a\+:','','')
3424 let host = substitute(host,'\..*$','','')
3425 if !exists('s:netrw_hup[host]')
3426 let s:netrw_hup[host]= {}
3427 endif
3428 let s:netrw_hup[host].uid = a:2
3429 let s:netrw_hup[host].passwd = a:3
3430 let g:netrw_uid = s:netrw_hup[host].uid
3431 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003432" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3433" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003435
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003436" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438
Bram Moolenaar85850f32019-07-19 22:05:51 +02003439" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003440" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003441" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003443" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003444" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3445fun! s:ExplorePatHls(pattern)
3446" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3447 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003449 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003450" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003451 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3452" call Dret("s:ExplorePatHls repat<".repat.">")
3453 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003454endfun
3455
3456" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003457" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003458" 0: (user: <mb>) bookmark current directory
3459" 1: (user: <gb>) change to the bookmarked directory
3460" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003461" 3: (browsing) records current directory history
3462" 4: (user: <u>) go up (previous) directory, using history
3463" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003464" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003465fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003466" 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 +02003467 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3468" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3469 return
3470 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003471
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003472 let ykeep = @@
3473 let curbufnr = bufnr("%")
3474
Bram Moolenaar9964e462007-05-05 17:54:07 +00003475 if a:chg == 0
3476 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003477" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003478 if exists("s:netrwmarkfilelist_{curbufnr}")
3479 call s:NetrwBookmark(0)
3480 echo "bookmarked marked files"
3481 else
3482 call s:MakeBookmark(a:curdir)
3483 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003484 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003485
KSR-Yasudaf4498252023-10-06 03:34:17 +09003486 try
3487 call s:NetrwBookHistSave()
3488 catch
3489 endtry
3490
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491 elseif a:chg == 1
3492 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003494 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003495" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003496 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003497 else
3498 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3499 endif
3500
3501 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003502" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003503 let didwork= 0
3504 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003506 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003507" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003508 let cnt= 1
3509 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003511 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003512 let didwork = 1
3513 let cnt = cnt + 1
3514 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003515 endif
3516
3517 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003518 " Note: history is saved only when PerformListing is done;
3519 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3520 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003521 let first = 1
3522 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003523 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003524 while ( first || cnt != g:netrw_dirhistcnt )
3525" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003527" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003528 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 let didwork= 1
3530 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003531 let histcnt = histcnt + 1
3532 let first = 0
3533 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003534 if cnt < 0
3535 let cnt= cnt + g:netrw_dirhistmax
3536 endif
3537 endwhile
3538 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003539 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003540 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003541 if didwork
3542 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3543 endif
3544
3545 elseif a:chg == 3
3546 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003547" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003548 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 +02003549 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3551 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003552 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003554 endif
3555
3556 elseif a:chg == 4
3557 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003558" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3561 if g:netrw_dirhistcnt < 0
3562 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003563 endif
3564 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003566 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003567 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3568" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003569 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003570 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003571" call Decho("setl ma noro",'~'.expand("<slnum>"))
3572 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003573 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003574" call Decho("setl nomod",'~'.expand("<slnum>"))
3575" 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 +00003576 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3578 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003579 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003581 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003582 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003585 echo "Sorry, no predecessor directory exists yet"
3586 endif
3587
3588 elseif a:chg == 5
3589 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003590" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003591 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003592 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3593 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3594" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003595 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003596" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003597 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598 sil! NetrwKeepj %d _
3599" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3600" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003601 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003602" 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 +02003603 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003604" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3605 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003606 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3608 if g:netrw_dirhistcnt < 0
3609 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003610 endif
3611 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003612 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003613 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003614 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003616 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003617
3618 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003619" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003620 if exists("s:netrwmarkfilelist_{curbufnr}")
3621 call s:NetrwBookmark(1)
3622 echo "removed marked files from bookmarks"
3623 else
3624 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003625 let iremove = v:count
3626 let dremove = g:netrw_bookmarklist[iremove - 1]
3627" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003628 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003629" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3630 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3631 echo "removed ".dremove." from g:netrw_bookmarklist"
3632" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003634" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003635
3636 try
3637 call s:NetrwBookHistSave()
3638 catch
3639 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003640 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003641 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003642 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003643 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003644" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003645endfun
3646
3647" ---------------------------------------------------------------------
3648" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003649" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003650" Sister function: s:NetrwBookHistSave()
3651fun! s:NetrwBookHistRead()
3652" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003653 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003654" 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 +02003655 return
3656 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003657 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003658
3659 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003660 if !exists("s:netrw_initbookhist")
3661 let home = s:NetrwHome()
3662 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003663 if filereadable(s:NetrwFile(savefile))
3664" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003665 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003666 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003667
3668 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003669 if g:netrw_dirhistmax > 0
3670 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003671 if filereadable(s:NetrwFile(savefile))
3672" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003673 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003674 endif
3675 let s:netrw_initbookhist= 1
3676 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003677 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003678 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003679
Bram Moolenaar97d62492012-11-15 21:28:22 +01003680 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3682" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683" call Dret("s:NetrwBookHistRead")
3684endfun
3685
3686" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003687" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688" Sister function: s:NetrwBookHistRead()
3689" I used to do this via viminfo but that appears to
3690" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003691" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3692" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003694fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003696 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003698 return
3699 endif
3700
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003704
3705 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003707" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003708 if g:netrw_use_noswf
3709 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3710 else
3711 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3712 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003713 setl nocin noai noci magic nospell nohid wig= noaw
3714 setl ma noro write
3715 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003716 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003717
Bram Moolenaar85850f32019-07-19 22:05:51 +02003718 " rename enew'd file: .netrwhist -- no attempt to merge
3719 " record dirhistmax and current dirhistcnt
3720 " save history
3721" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003722 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003723 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003724 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3725 if g:netrw_dirhistmax > 0
3726 let lastline = line("$")
3727 let cnt = g:netrw_dirhistcnt
3728 let first = 1
3729 while ( first || cnt != g:netrw_dirhistcnt )
3730 let lastline= lastline + 1
3731 if exists("g:netrw_dirhist_{cnt}")
3732 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3733" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3734 endif
3735 let first = 0
3736 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3737 if cnt < 0
3738 let cnt= cnt + g:netrw_dirhistmax
3739 endif
3740 endwhile
3741 exe "sil! w! ".savefile
3742" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3743 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744
Bram Moolenaar85850f32019-07-19 22:05:51 +02003745 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003746 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003748" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749 " merge and write .netrwbook
3750 let savefile= s:NetrwHome()."/.netrwbook"
3751
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003752 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003753 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003754 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 for bdm in booklist
3756 if index(g:netrw_bookmarklist,bdm) == -1
3757 call add(g:netrw_bookmarklist,bdm)
3758 endif
3759 endfor
3760 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003761 endif
3762
3763 " construct and save .netrwbook
3764 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003765 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003766" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003767 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003768
3769 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003770 let bgone= bufnr("%")
3771 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003772 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003773
3774" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003775endfun
3776
3777" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3779" list of the contents of a local or remote directory. It is assumed that the
3780" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3781" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003782" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003783fun! s:NetrwBrowse(islocal,dirname)
3784 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003785" 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 +02003786" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3787" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3788" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003789
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003790 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3791 " This is useful when one edits a local file, then :e ., then :Rex
3792 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3793 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003794" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003795 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003796
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003797 " s:NetrwBrowse : initialize history {{{3
3798 if !exists("s:netrw_initbookhist")
3799 NetrwKeepj call s:NetrwBookHistRead()
3800 endif
3801
3802 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003803 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003804 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003805" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003806 else
3807 let dirname= a:dirname
3808 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003809
Bram Moolenaar85850f32019-07-19 22:05:51 +02003810 " repoint t:netrw_lexbufnr if appropriate
3811 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3812" call Decho("set repointlexbufnr to true!")
3813 let repointlexbufnr= 1
3814 endif
3815
3816 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 if exists("s:netrw_skipbrowse")
3818 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003819" 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 +01003820" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003821 return
3822 endif
3823 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003825" call Dret("s:NetrwBrowse : missing shellescape()")
3826 return
3827 endif
3828 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003830" call Dret("s:NetrwBrowse : missing fnameescape()")
3831 return
3832 endif
3833
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003835 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003836
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003837 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003838 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3839 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3840" call Decho("clearing marked files",'~'.expand("<slnum>"))
3841 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3842 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003843 endif
3844
3845 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003846 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003847" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3848" 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 +02003849 if s:NetrwLcd(dirname)
3850" call Dret("s:NetrwBrowse : lcd failure")
3851 return
3852 endif
3853 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003855
Bram Moolenaar5c736222010-01-06 20:54:52 +01003856 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003858" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003862 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003864" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865
3866 " remove any filetype indicator from end of dirname, except for the
3867 " "this is a directory" indicator (/).
3868 " There shouldn't be one of those here, anyway.
3869 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 call s:RemotePathAnalysis(dirname)
3872
3873 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3874 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003875 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003877" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 let b:netrw_curdir = dirname
3879 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003880 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3882 sil call netrw#NetRead(2,url)
3883 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003884" call Decho("url<".url.">",'~'.expand("<slnum>"))
3885" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3886" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003887 if s:path =~ '.bz2'
3888 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3889 elseif s:path =~ '.gz'
3890 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3891 elseif s:path =~ '.gz'
3892 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3893 else
3894 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3895 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 endif
3897
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003898 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003899 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003900 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003902 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003903" 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 +00003904
Bram Moolenaar446cb832008-06-24 21:56:24 +00003905" call Dret("s:NetrwBrowse : file<".s:fname.">")
3906 return
3907 endif
3908
Bram Moolenaaradc21822011-04-01 18:03:16 +02003909 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003910 call s:UseBufWinVars()
3911
3912 " set up some variables {{{3
3913 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003914 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915 let s:last_sort_by = g:netrw_sort_by
3916
3917 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003918 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003919
Bram Moolenaar97d62492012-11-15 21:28:22 +01003920 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003922 let svpos = winsaveview()
3923" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003925
Bram Moolenaar446cb832008-06-24 21:56:24 +00003926 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003927 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3928 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3929" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3930" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3931 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3932 else
3933" " call Decho("2match none",'~'.expand("<slnum>"))
3934 2match none
3935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003936 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003937 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003938 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003940 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" 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 +01003942" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003943 return
3944 endif
3945
3946 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003947" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003948 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 if b:netrw_curdir =~ '[/\\]$'
3950 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3951 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003952 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003953 let b:netrw_curdir= b:netrw_curdir."/"
3954 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003955 if b:netrw_curdir == ''
3956 if has("amiga")
3957 " On the Amiga, the empty string connotes the current directory
3958 let b:netrw_curdir= getcwd()
3959 else
3960 " under unix, when the root directory is encountered, the result
3961 " from the preceding substitute is an empty string.
3962 let b:netrw_curdir= '/'
3963 endif
3964 endif
3965 if !a:islocal && b:netrw_curdir !~ '/$'
3966 let b:netrw_curdir= b:netrw_curdir.'/'
3967 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003969
3970 " ------------
3971 " (local only) {{{3
3972 " ------------
3973 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975
3976 " Set up ShellCmdPost handling. Append current buffer to browselist
3977 call s:LocalFastBrowser()
3978
3979 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3980 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003981" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3982" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003983 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003984 if s:NetrwLcd(b:netrw_curdir)
3985" call Dret("s:NetrwBrowse : lcd failure")
3986 return
3987 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 endif
3989 endif
3990
3991 " --------------------------------
3992 " remote handling: {{{3
3993 " --------------------------------
3994 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996
Bram Moolenaar97d62492012-11-15 21:28:22 +01003997 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003998" 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 +02003999 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004000 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4003 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4004 if dirname !~ '/$'
4005 let dirname= dirname.'/'
4006 endif
4007 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004008" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004009 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004010 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004012 endif
4013
4014 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4015 if dirname !~ dirpat
4016 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004017 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004018 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004019 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004020" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004021 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004022" 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 +00004023" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4024 return
4025 endif
4026 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004027" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004028 endif " (additional remote handling)
4029
Bram Moolenaar85850f32019-07-19 22:05:51 +02004030 " -------------------------------
4031 " Perform Directory Listing: {{{3
4032 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004033 NetrwKeepj call s:NetrwMaps(a:islocal)
4034 NetrwKeepj call s:NetrwCommands(a:islocal)
4035 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004037 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004038 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004039" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4040
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004041 " If there is a rexposn: restore position with rexposn
4042 " Otherwise : set rexposn
4043 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004044" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4045 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4046 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4047 NetrwKeepj exe w:netrw_bannercnt
4048 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004049 else
4050 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4051 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004052 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004053 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004055 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004056 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004057
Bram Moolenaar85850f32019-07-19 22:05:51 +02004058 " repoint t:netrw_lexbufnr if appropriate
4059 if exists("repointlexbufnr")
4060 let t:netrw_lexbufnr= bufnr("%")
4061" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4062 endif
4063
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004064 " restore position
4065 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004066" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4067 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004068 endif
4069
Bram Moolenaara6878372014-03-22 21:02:50 +01004070 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004071 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4072 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4074" 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 +02004075" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004076 return
4077endfun
4078
4079" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004080" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4081" may not apply correctly; ie. netrw's idea of the current directory may
4082" differ from vim's. This function insures that netrw's idea of the current
4083" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004084" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004085fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004086" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4087" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4088" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4089" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4090" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004091
4092 " clean up any leading treedepthstring
4093 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4094 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004095" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004096 else
4097 let fname= a:fname
4098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004099
4100 if g:netrw_keepdir
4101 " vim's idea of the current directory possibly may differ from netrw's
4102 if !exists("b:netrw_curdir")
4103 let b:netrw_curdir= getcwd()
4104 endif
4105
Nir Lichtman1e34b952024-05-08 19:19:34 +02004106 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004107 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004109 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004110" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111 else
4112 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004114" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115 endif
4116
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004120" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 else
4122 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004123 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004124" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125 endif
4126 else
4127 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4130" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4131" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004132 endif
4133
Bram Moolenaar85850f32019-07-19 22:05:51 +02004134" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004135 return ret
4136endfun
4137
4138" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004139" s:NetrwFileInfo: supports qf (query for file information) {{{2
4140fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004141" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004142 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004143 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004145 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004147 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004148 let lsopt= "-lsadh --si"
4149 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004150" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004151 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004152
4153 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004156
Bram Moolenaara6878372014-03-22 21:02:50 +01004157 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004158 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004160
4161 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004162 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004163" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004164
Bram Moolenaar446cb832008-06-24 21:56:24 +00004165 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004167 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004169 endif
4170 else
4171 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4173 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174 let fname= substitute(a:fname,".$","","")
4175 else
4176 let fname= a:fname
4177 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004178 let t = getftime(s:NetrwFile(fname))
4179 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004180 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004181 let sz= s:NetrwHumanReadable(sz)
4182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004183 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4184" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004185 endif
4186 else
4187 echo "sorry, \"qf\" not supported yet for remote files"
4188 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004189 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004190" call Dret("s:NetrwFileInfo")
4191endfun
4192
4193" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004194" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4195fun! s:NetrwFullPath(filename)
4196" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4197 let filename= a:filename
4198 if filename !~ '^/'
4199 let filename= resolve(getcwd().'/'.filename)
4200 endif
4201 if filename != "/" && filename =~ '/$'
4202 let filename= substitute(filename,'/$','','')
4203 endif
4204" " call Dret("s:NetrwFullPath <".filename.">")
4205 return filename
4206endfun
4207
4208" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004209" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004210" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004211" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004212" 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 +00004213fun! s:NetrwGetBuffer(islocal,dirname)
4214" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004215" 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 +02004216" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4217" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004218 let dirname= a:dirname
4219
4220 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004221" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004222 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004223" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004224 let s:netrwbuf= {}
4225 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004226" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4227" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4228
4229 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4230 let bufnum = -1
4231
4232 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4233 if has_key(s:netrwbuf,"NetrwTreeListing")
4234 let bufnum= s:netrwbuf["NetrwTreeListing"]
4235 else
4236 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4237 endif
4238" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4239 if !bufexists(bufnum)
4240 call remove(s:netrwbuf,"NetrwTreeListing"])
4241 let bufnum= -1
4242 endif
4243 elseif bufnr("NetrwTreeListing") != -1
4244 let bufnum= bufnr("NetrwTreeListing")
4245" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4246 else
4247" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4248 let bufnum= -1
4249 endif
4250
4251 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004252 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004253" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004254 if !bufexists(bufnum)
4255 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4256 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258
Bram Moolenaar446cb832008-06-24 21:56:24 +00004259 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004261 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4264
Bram Moolenaar71badf92023-04-22 22:40:14 +01004265 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004266 " IF the buffer already has the desired name
4267 " AND it is empty
4268 let curbuf = bufname("%")
4269 if curbuf == '.'
4270 let curbuf = getcwd()
4271 endif
4272" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004273" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004274" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4275" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4276" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4277" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4278 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004279" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4280 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004281 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004282" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004283 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004284 " 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 +00004285
4286 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004287 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" 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 +00004289 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 " name the buffer
4292 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4293 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004294" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004295 let w:netrw_treebufnr = bufnr("%")
4296 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004297 if g:netrw_use_noswf
4298 setl nobl bt=nofile noswf
4299 else
4300 setl nobl bt=nofile
4301 endif
4302 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4303 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4304 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4305 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004306" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004308 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004309 " enter the new buffer into the s:netrwbuf dictionary
4310 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4311" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4312" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004314" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315
4316 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004317" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004318 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004320 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004321
4322 if &ft == "netrw"
4323" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4324 exe "sil! NetrwKeepj noswapfile b ".bufnum
4325" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004327" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4328 call s:NetrwEditBuf(bufnum)
4329" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004333 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004335
4336 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004338
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339 if line("$") <= 1 && getline(1) == ""
4340 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004341 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004342" 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>"))
4343" 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 +01004344" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4345 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004346
Bram Moolenaar97d62492012-11-15 21:28:22 +01004347 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004348" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004349 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350 sil NetrwKeepj %d _
4351" 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>"))
4352" 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 +01004353" 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 +00004354 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004355
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004357" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4358" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004359 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004361 NetrwKeepj call s:NetrwListSettings(a:islocal)
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>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004364" 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 +00004365 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004366
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004368" 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>"))
4369" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4370" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 return 1
4372 endif
4373 endif
4374
4375 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4376 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4377 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4378 " med 1 D H
4379 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" 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 +00004381 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004382 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004383 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004384
4385 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004386" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4387" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4388 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004390" 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>"))
4391" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4392" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393 return 0
4394endfun
4395
4396" ---------------------------------------------------------------------
4397" s:NetrwGetcwd: get the current directory. {{{2
4398" Change backslashes to forward slashes, if any.
4399" If doesc is true, escape certain troublesome characters
4400fun! s:NetrwGetcwd(doesc)
4401" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4402 let curdir= substitute(getcwd(),'\\','/','ge')
4403 if curdir !~ '[\/]$'
4404 let curdir= curdir.'/'
4405 endif
4406 if a:doesc
4407 let curdir= fnameescape(curdir)
4408 endif
4409" call Dret("NetrwGetcwd <".curdir.">")
4410 return curdir
4411endfun
4412
4413" ---------------------------------------------------------------------
4414" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4415fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004416" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4417" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4418 let keepsol= &l:sol
4419 setl nosol
4420
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421 call s:UseBufWinVars()
4422
4423 " insure that w:netrw_liststyle is set up
4424 if !exists("w:netrw_liststyle")
4425 if exists("g:netrw_liststyle")
4426 let w:netrw_liststyle= g:netrw_liststyle
4427 else
4428 let w:netrw_liststyle= s:THINLIST
4429 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004430" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 endif
4432
4433 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4434 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004435" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004436 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004437 let dirname= "./"
4438 let curline= getline('.')
4439
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004440 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004441 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 let s:netrw_skipbrowse= 1
4443 echo 'Pressing "s" also works'
4444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446 let s:netrw_skipbrowse= 1
4447 echo 'Press "S" to edit sorting sequence'
4448
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004449 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004450 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004453 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004454 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455 let s:netrw_skipbrowse= 1
4456 echo 'Pressing "a" also works'
4457
4458 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004459 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460 endif
4461
4462 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004463" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004464 NetrwKeepj norm! 0
4465 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466
4467 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004469 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004470 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4471
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004472 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004473" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004474 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004475 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476
4477 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004478" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004479 let dirname= getline('.')
4480
4481 if !exists("b:netrw_cpf")
4482 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004483 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 +01004484 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004485" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 endif
4487
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4491" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004493 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 else
4495 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 endif
4498 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004499 let eofname= filestart + b:netrw_cpf + 1
4500 if eofname <= col("$")
4501 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004502 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004503 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004506 let dirname = @a
4507 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004508" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 endif
4512
4513 " symlinks are indicated by a trailing "@". Remove it before further processing.
4514 let dirname= substitute(dirname,"@$","","")
4515
4516 " executables are indicated by a trailing "*". Remove it before further processing.
4517 let dirname= substitute(dirname,"\*$","","")
4518
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004519 let &l:sol= keepsol
4520
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521" call Dret("s:NetrwGetWord <".dirname.">")
4522 return dirname
4523endfun
4524
4525" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004526" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4527" g:netrw_bufsettings will be used after the listing is produced.
4528" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529fun! s:NetrwListSettings(islocal)
4530" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531" 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 +00004532 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004533" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4534 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4535 setl bt=nofile nobl ma nonu nowrap noro nornu
4536 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004538 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004539 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004540" call Dredir("ls!","s:NetrwListSettings")
4541" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004542 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004543 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004545 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004547 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004549" 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 +00004550" call Dret("s:NetrwListSettings")
4551endfun
4552
4553" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004554" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555" islocal=0: remote browsing
4556" =1: local browsing
4557fun! s:NetrwListStyle(islocal)
4558" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004559
Bram Moolenaar97d62492012-11-15 21:28:22 +01004560 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561 let fname = s:NetrwGetWord()
4562 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004563 let svpos = winsaveview()
4564" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004566" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4567" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4568" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569
Bram Moolenaar85850f32019-07-19 22:05:51 +02004570 " repoint t:netrw_lexbufnr if appropriate
4571 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4572" call Decho("set repointlexbufnr to true!")
4573 let repointlexbufnr= 1
4574 endif
4575
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 if w:netrw_liststyle == s:THINLIST
4577 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004578" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004579 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4580
4581 elseif w:netrw_liststyle == s:LONGLIST
4582 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004583" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4585
4586 elseif w:netrw_liststyle == s:WIDELIST
4587 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004588" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4590
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004591 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004592" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4594
4595 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004596 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_liststyle = s:THINLIST
4598 let w:netrw_liststyle = g:netrw_liststyle
4599 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4600 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004601 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004602" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004603
4604 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004605" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4606 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004607 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004608" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004609 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" 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 +00004611
4612 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004614 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004615 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616
Bram Moolenaar85850f32019-07-19 22:05:51 +02004617 " repoint t:netrw_lexbufnr if appropriate
4618 if exists("repointlexbufnr")
4619 let t:netrw_lexbufnr= bufnr("%")
4620" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4621 endif
4622
Bram Moolenaar13600302014-05-22 18:26:40 +02004623 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004624" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4625 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004626 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004627
4628" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4629endfun
4630
4631" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004632" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4633fun! s:NetrwBannerCtrl(islocal)
4634" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4635
Bram Moolenaar97d62492012-11-15 21:28:22 +01004636 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004637 " toggle the banner (enable/suppress)
4638 let g:netrw_banner= !g:netrw_banner
4639
4640 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004641 let svpos= winsaveview()
4642" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004643 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4644
4645 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004646 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4647 let fname= s:NetrwGetWord()
4648 sil NetrwKeepj $
4649 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4650" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4651 if result <= 0 && exists("w:netrw_bannercnt")
4652 exe "NetrwKeepj ".w:netrw_bannercnt
4653 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004654 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004655 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004656" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4657endfun
4658
4659" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004660" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4661"
4662" No bang: enters files/directories into Netrw's bookmark system
4663" No argument and in netrw buffer:
4664" if there are marked files: bookmark marked files
4665" otherwise : bookmark file/directory under cursor
4666" No argument and not in netrw buffer: bookmarks current open file
4667" Has arguments: globs them individually and bookmarks them
4668"
4669" With bang: deletes files/directories from Netrw's bookmark system
4670fun! s:NetrwBookmark(del,...)
4671" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4672 if a:0 == 0
4673 if &ft == "netrw"
4674 let curbufnr = bufnr("%")
4675
4676 if exists("s:netrwmarkfilelist_{curbufnr}")
4677 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004678" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004679 let svpos = winsaveview()
4680" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004681 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004682 for fname in s:netrwmarkfilelist_{curbufnr}
4683 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4684 endfor
4685 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4686 call s:NetrwUnmarkList(curbufnr,curdir)
4687 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004688" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4689 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004690 else
4691 let fname= s:NetrwGetWord()
4692 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4693 endif
4694
4695 else
4696 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004697" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004698 let fname= expand("%")
4699 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4700 endif
4701
4702 else
4703 " bookmark specified files
4704 " attempts to infer if working remote or local
4705 " by deciding if the current file begins with an url
4706 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004707 let islocal= expand("%") !~ '^\a\{3,}://'
4708" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004709 let i = 1
4710 while i <= a:0
4711 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004712 if v:version > 704 || (v:version == 704 && has("patch656"))
4713 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004714 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004715 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004717 else
4718 let mbfiles= [a:{i}]
4719 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4724 endfor
4725 let i= i + 1
4726 endwhile
4727 endif
4728
4729 " update the menu
4730 call s:NetrwBookmarkMenu()
4731
4732" call Dret("s:NetrwBookmark")
4733endfun
4734
4735" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004736" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4737" .2.[cnt] for bookmarks, and
4738" .3.[cnt] for history
4739" (see s:NetrwMenu())
4740fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004741 if !exists("s:netrw_menucnt")
4742 return
4743 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004744" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004745
4746 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004747 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004748 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004749" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004750 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4751 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004752 endif
4753 if !exists("s:netrw_initbookhist")
4754 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004755 endif
4756
4757 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004758 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004759 let cnt= 1
4760 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004761" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004762 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004763
4764 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004765 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004766
4767 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004768 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 +01004769 let cnt= cnt + 1
4770 endfor
4771
4772 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004773
4774 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004775 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004776 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004777 let first = 1
4778 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004779 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004780 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 if exists("g:netrw_dirhist_{cnt}")
4783 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4786 endif
4787 let first = 0
4788 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4789 if cnt < 0
4790 let cnt= cnt + g:netrw_dirhistmax
4791 endif
4792 endwhile
4793 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004794
Bram Moolenaar9964e462007-05-05 17:54:07 +00004795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004796" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004797endfun
4798
4799" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004800" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4801" directory and a new directory name. Also, if the
4802" "new directory name" is actually a file,
4803" NetrwBrowseChgDir() edits the file.
4804fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004805" 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 +01004806" 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 +00004807
Bram Moolenaar97d62492012-11-15 21:28:22 +01004808 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004809 if !exists("b:netrw_curdir")
4810 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4811 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004812 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004813" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4814" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004815" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004818 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004819" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004820
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004821 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004822" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004823 call s:SavePosn(s:netrw_posn)
4824 NetrwKeepj call s:NetrwOptionsSave("s:")
4825 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004826 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004827 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004828 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004829 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004830 endif
4831 let newdir = a:newdir
4832 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004833 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004834" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004835" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004836" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004837
4838 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004839" 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 +01004840 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004841" 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 +01004842 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004843 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004844" 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 +01004845 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004846" 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 +02004847 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004848 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004849 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004850 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" 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 +01004852 endif
4853 endif
4854" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004855" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004856 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004857
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 " set up o/s-dependent directory recognition pattern
4859 if has("amiga")
4860 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004861 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 let dirpat= '[\/]$'
4863 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004864" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865
4866 if dirname !~ dirpat
4867 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004868 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004870" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871 endif
4872
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004873" 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 +01004874 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004875 " ------------------------------
4876 " NetrwBrowseChgDir: edit a file {{{3
4877 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004878" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004879
Bram Moolenaar97d62492012-11-15 21:28:22 +01004880 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004881 let s:rexposn_{bufnr("%")}= winsaveview()
4882" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4884" 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 +01004885
Bram Moolenaar446cb832008-06-24 21:56:24 +00004886 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4888" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004889" let newdir = s:NetrwTreePath(s:netrw_treetop)
4890" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004891 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004892 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4893" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4894 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895 if dirname =~ '/$'
4896 let dirname= dirname.newdir
4897 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004898 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004900" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4901" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004903" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004905 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004908" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004909 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004911" 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 +02004912 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004913 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004915" " 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 +01004916 if type(g:netrw_browse_split) == 3
4917 " open file in server
4918 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004919" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004920 call s:NetrwServerEdit(a:islocal,dirname)
4921" call Dret("s:NetrwBrowseChgDir")
4922 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004923
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004924 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004925 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004926" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004927 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4928 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004929 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004930 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004931 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004932 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004933
Bram Moolenaar446cb832008-06-24 21:56:24 +00004934 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004935 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004936" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004937 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4938 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004939 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004940 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004941 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004942 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004943
Bram Moolenaar446cb832008-06-24 21:56:24 +00004944 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004945 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004946" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004947 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004948 if !exists("b:netrw_curdir")
4949 let b:netrw_curdir= getcwd()
4950 endif
4951 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004952
Bram Moolenaar446cb832008-06-24 21:56:24 +00004953 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004954 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004955" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004956 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004957 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004959 return
4960 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004961 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004962
Bram Moolenaar9964e462007-05-05 17:54:07 +00004963 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004964 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004965" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 call s:NetrwMenu(0)
4967 " optional change to window
4968 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004969" 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 +02004970 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004971 " if g:netrw_chgwin is set to one more than the last window, then
4972 " vertically split the last window to make that window available.
4973 let curwin= winnr()
4974 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4975 vs
4976 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004977 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004978 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004979 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004980 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004981 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004982
Bram Moolenaar9964e462007-05-05 17:54:07 +00004983 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004984
Bram Moolenaar446cb832008-06-24 21:56:24 +00004985 " the point where netrw actually edits the (local) file
4986 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004987 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004988 if !&mod
4989 " if e the new file would fail due to &mod, then don't change any of the flags
4990 let dolockout= 1
4991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004992 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004993" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004994 " some like c-^ to return to the last edited file
4995 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004996 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4997 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004998 call s:NetrwEditFile("e","",dirname)
4999" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005000 " COMBAK -- cuc cul related
5001 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005002 if &hidden || &bufhidden == "hide"
5003 " file came from vim's hidden storage. Don't "restore" options with it.
5004 let dorestore= 0
5005 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005006 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005007" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005008 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005009
5010 " handle g:Netrw_funcref -- call external-to-netrw functions
5011 " This code will handle g:Netrw_funcref as an individual function reference
5012 " or as a list of function references. It will ignore anything that's not
5013 " a function reference. See :help Funcref for information about function references.
5014 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005015" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005016 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005018 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005019 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005022 if type(Fncref) == 2
5023 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 endif
5025 endfor
5026 endif
5027 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005028 endif
5029
5030 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005031 " ----------------------------------------------------
5032 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5033 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005034" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005035 let dirname = newdir
5036 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005037 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005039
5040 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005041 " ---------------------------------------------
5042 " NetrwBrowseChgDir: refresh the directory list {{{3
5043 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005044" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005045 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005046 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047
5048 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005049 " --------------------------------------
5050 " NetrwBrowseChgDir: go up one directory {{{3
5051 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005052" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005053
5054 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5055 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005056" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5057" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005058 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005059 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005060 endif
5061
5062 if has("amiga")
5063 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005064" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005065 if a:islocal
5066 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5067 let dirname= substitute(dirname,'/$','','')
5068 else
5069 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5070 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005072
Nir Lichtman1e34b952024-05-08 19:19:34 +02005073 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005074 " windows
5075 if a:islocal
5076 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5077 if dirname == ""
5078 let dirname= '/'
5079 endif
5080 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005081 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005082 endif
5083 if dirname =~ '^\a:$'
5084 let dirname= dirname.'/'
5085 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005086" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005087
Bram Moolenaar446cb832008-06-24 21:56:24 +00005088 else
5089 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005090" 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 +00005091 if a:islocal
5092 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5093 if dirname == ""
5094 let dirname= '/'
5095 endif
5096 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005097 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005101 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005102 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103
5104 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005105 " --------------------------------------
5106 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5107 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005108" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005109 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5110" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005111 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005112 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5114 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005116 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005118 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005119 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005120" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005121
5122 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005123" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005125" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 let haskey= 1
5127 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005128" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 endif
5130
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005131 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005132" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005133 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 if has_key(w:netrw_treedict,treedir."/")
5135 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 let haskey = 1
5138 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005139" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005140 endif
5141 endif
5142
5143 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005144" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 if !haskey && treedir =~ '/$'
5146 let treedir= substitute(treedir,'/$','','')
5147 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005148" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 let haskey = 1
5150 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 endif
5153 endif
5154
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005155" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 if haskey
5157 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5161" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005162 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 else
5164 " go down one directory
5165 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5167" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005169 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005170" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005171 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172
5173 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005174 " ----------------------------------------
5175 " NetrwBrowseChgDir: Go down one directory {{{3
5176 " ----------------------------------------
5177 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005179 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005180 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005181 endif
5182
Bram Moolenaar97d62492012-11-15 21:28:22 +01005183 " --------------------------------------
5184 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5185 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005186 if dorestore
5187 " dorestore is zero'd when a local file was hidden or bufhidden;
5188 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005189" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005190 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005191" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005193 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005194 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005195" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005196 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5198" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005199 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" 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 +02005201 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5203" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005204 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" 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 +02005206 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005207 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005208 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005209 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005210
Bram Moolenaar446cb832008-06-24 21:56:24 +00005211" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5212 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005213endfun
5214
5215" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005216" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5217" for thin, long, and wide: cursor placed just after banner
5218" for tree, keeps cursor on current filename
5219fun! s:NetrwBrowseUpDir(islocal)
5220" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005221 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5222 " this test needed because occasionally this function seems to be incorrectly called
5223 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005224 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005225 " directories.
5226" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5227 return
5228 endif
5229
Bram Moolenaara6878372014-03-22 21:02:50 +01005230 norm! 0
5231 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005233 let curline= getline(".")
5234 let swwline= winline() - 1
5235 if exists("w:netrw_treetop")
5236 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005237 elseif exists("b:netrw_curdir")
5238 let w:netrw_treetop= b:netrw_curdir
5239 else
5240 let w:netrw_treetop= getcwd()
5241 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005242 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005243 let curfile = getline(".")
5244 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005245 if a:islocal
5246 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5247 else
5248 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5249 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005250" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5251" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5252 if w:netrw_treetop == '/'
5253 keepj call search('^\M'.curfile,"w")
5254 elseif curfile == '../'
5255 keepj call search('^\M'.curfile,"wb")
5256 else
5257" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5258 while 1
5259 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5260 let treepath= s:NetrwTreePath(w:netrw_treetop)
5261" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5262 if treepath == curpath
5263 break
5264 endif
5265 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005266 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005267
Bram Moolenaara6878372014-03-22 21:02:50 +01005268 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005269" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005270 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005271 if exists("b:netrw_curdir")
5272 let curdir= b:netrw_curdir
5273 else
5274 let curdir= expand(getcwd())
5275 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005276 if a:islocal
5277 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5278 else
5279 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5280 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005281 call s:RestorePosn(s:netrw_posn)
5282 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005283 let curdir= '\<'. escape(curdir, '~'). '/'
5284 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005285 endif
5286" call Dret("s:NetrwBrowseUpDir")
5287endfun
5288
5289" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005290" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005291" given filename; typically this means given their extension.
5292" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005293fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005294 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005295" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005296
Bram Moolenaar91359012019-11-30 17:57:03 +01005297 if a:remote == 0 && isdirectory(a:fname)
5298 " if its really just a local directory, then do a "gf" instead
5299" 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 +01005300" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5301 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005302" call Dret("netrw#BrowseX")
5303 return
5304 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5305 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5306" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5307" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5308" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5309" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5310 norm! gf
5311" call Dret("netrw#BrowseX")
5312 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005313 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005314" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005315
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005316 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5317 let remote = a:remote
5318 else
5319 let remote = 0
5320 endif
5321
Bram Moolenaar97d62492012-11-15 21:28:22 +01005322 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005323 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005324" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005325
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005326 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5327 let awkeep = &aw
5328 set noaw
5329
Bram Moolenaar5c736222010-01-06 20:54:52 +01005330 " special core dump handler
5331 if a:fname =~ '/core\(\.\d\+\)\=$'
5332 if exists("g:Netrw_corehandler")
5333 if type(g:Netrw_corehandler) == 2
5334 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005335" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005336 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005337 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005338 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005339" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005341 if type(Fncref) == 2
5342 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 endif
5344 endfor
5345 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005346" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005347 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005348 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005349 let &aw= awkeep
5350" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005351 return
5352 endif
5353 endif
5354
Bram Moolenaar446cb832008-06-24 21:56:24 +00005355 " set up the filename
5356 " (lower case the extension, make a local copy of a remote file)
5357 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005358 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005359 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005360 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005361 if exten =~ "[\\/]"
5362 let exten= ""
5363 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005364" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005365
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005366 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005368" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005369 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005370 call netrw#NetRead(3,a:fname)
5371 " attempt to rename tempfile
5372 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005373 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005374" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5375" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005376 if s:netrw_tmpfile != newname && newname != ""
5377 if rename(s:netrw_tmpfile,newname) == 0
5378 " renaming succeeded
5379" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5380 let fname= newname
5381 else
5382 " renaming failed
5383" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5384 let fname= s:netrw_tmpfile
5385 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005386 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005387 let fname= s:netrw_tmpfile
5388 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005389 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005390" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005391 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005392 " special ~ handler for local
5393 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005394" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5395 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005396 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005397 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005398" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5399" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005400
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005401 " set up redirection (avoids browser messages)
5402 " by default, g:netrw_suppress_gx_mesg is true
5403 if g:netrw_suppress_gx_mesg
5404 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005405 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005406 let redir= substitute(&srr,"%s","nul","")
5407 else
5408 let redir= substitute(&srr,"%s","/dev/null","")
5409 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005410 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005411 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005413 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005414 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005415 else
5416 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005418" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005420 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005422" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423 if g:netrw_browsex_viewer =~ '\s'
5424 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5425 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5426 let oviewer = ''
5427 let cnt = 1
5428 while !executable(viewer) && viewer != oviewer
5429 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5430 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5431 let cnt = cnt + 1
5432 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005433" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434 endwhile
5435 else
5436 let viewer = g:netrw_browsex_viewer
5437 let viewopt = ""
5438 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005439" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005440 endif
5441
5442 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005443" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005444 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005445" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 let ret= netrwFileHandlers#Invoke(exten,fname)
5447
5448 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005449" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005450 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 let ret= v:shell_error
5452
Nir Lichtman1e34b952024-05-08 19:19:34 +02005453 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005454" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005455 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005456 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005457 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005458 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005459 else
5460 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5461 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005462 let ret= v:shell_error
5463
Bram Moolenaar97d62492012-11-15 21:28:22 +01005464 elseif has("win32unix")
5465 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005466" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005467 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005468" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005469 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005470 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005472 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005473 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005474" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005475 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005476 else
5477 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5478 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005479 let ret= v:shell_error
5480
Bram Moolenaar85850f32019-07-19 22:05:51 +02005481 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005482" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5483 if a:fname =~ '^https\=://'
5484 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5485 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005486" call Decho("fname<".fname.">")
5487" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005488 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5489
5490 else
5491 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5492 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005493 let ret= v:shell_error
5494
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005495 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5496" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5497 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5498 let ret= v:shell_error
5499
5500 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5501" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5502 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5503 let ret= v:shell_error
5504
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005505 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005506" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005507 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005508 let ret= v:shell_error
5509
5510 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005511" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005512 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005513 let ret= v:shell_error
5514
5515 else
5516 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005517" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005518 let ret= netrwFileHandlers#Invoke(exten,fname)
5519 endif
5520
5521 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5522 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005523" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005524 let ret= netrwFileHandlers#Invoke(exten,fname)
5525 endif
5526
Bram Moolenaarc236c162008-07-13 17:41:49 +00005527 " restoring redraw! after external file handlers
5528 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005529
5530 " cleanup: remove temporary file,
5531 " delete current buffer if success with handler,
5532 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005533 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005534 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005535" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005536"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005537" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005538" endif
5539
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005540 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005541 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005543 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005545 if use_ctrlo
5546 exe "sil! NetrwKeepj norm! \<c-o>"
5547 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005549" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005550 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005551 let @@ = ykeep
5552 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005554" call Dret("netrw#BrowseX")
5555endfun
5556
5557" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005558" netrw#GX: gets word under cursor for gx support {{{2
5559" See also: netrw#BrowseXVis
5560" netrw#BrowseX
5561fun! netrw#GX()
5562" call Dfunc("netrw#GX()")
5563 if &ft == "netrw"
5564 let fname= s:NetrwGetWord()
5565 else
5566 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5567 endif
5568" call Dret("netrw#GX <".fname.">")
5569 return fname
5570endfun
5571
5572" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005573" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5574fun! netrw#BrowseXVis()
5575" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005576 let akeep = @a
5577 norm! gv"ay
5578 let gxfile= @a
5579 let @a = akeep
5580 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005581" call Dret("netrw#BrowseXVis")
5582endfun
5583
5584" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005585" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5586" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5587" to become an unlisted buffer, so in that case don't bwipe it.
5588fun! s:NetrwBufRename(newname)
5589" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5590" call Dredir("ls!","s:NetrwBufRename (before rename)")
5591 let oldbufname= bufname(bufnr("%"))
5592" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5593
5594 if oldbufname != a:newname
5595" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5596 let b:junk= 1
5597" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5598 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005599" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005600 let oldbufnr= bufnr(oldbufname)
5601" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5602" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5603 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5604" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5605 exe "bwipe! ".oldbufnr
5606" else " Decho
5607" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005608" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5609" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5610" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005611 endif
5612" call Dredir("ls!","s:NetrwBufRename (after rename)")
5613" else " Decho
5614" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5615 endif
5616
5617" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5618endfun
5619
5620" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005621" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005622fun! netrw#CheckIfRemote(...)
5623" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5624 if a:0 > 0
5625 let curfile= a:1
5626 else
5627 let curfile= expand("%")
5628 endif
5629" call Decho("curfile<".curfile.">")
5630 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005631" call Dret("netrw#CheckIfRemote 1")
5632 return 1
5633 else
5634" call Dret("netrw#CheckIfRemote 0")
5635 return 0
5636 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005637endfun
5638
5639" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005640" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5641fun! s:NetrwChgPerm(islocal,curdir)
5642" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005643 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005644 call inputsave()
5645 let newperm= input("Enter new permission: ")
5646 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005647 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5648 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5649" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005650 call system(chgperm)
5651 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005652 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005653 endif
5654 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005655 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005656 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005657 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658" call Dret("s:NetrwChgPerm")
5659endfun
5660
5661" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005662" s:CheckIfKde: checks if kdeinit is running {{{2
5663" Returns 0: kdeinit not running
5664" 1: kdeinit is running
5665fun! s:CheckIfKde()
5666" call Dfunc("s:CheckIfKde()")
5667 " seems kde systems often have gnome-open due to dependencies, even though
5668 " gnome-open's subsidiary display tools are largely absent. Kde systems
5669 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5670 if !exists("s:haskdeinit")
5671 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005672 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005673 if v:shell_error
5674 let s:haskdeinit = 0
5675 endif
5676 else
5677 let s:haskdeinit= 0
5678 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005679" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005680 endif
5681
5682" call Dret("s:CheckIfKde ".s:haskdeinit)
5683 return s:haskdeinit
5684endfun
5685
5686" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005687" s:NetrwClearExplore: clear explore variables (if any) {{{2
5688fun! s:NetrwClearExplore()
5689" call Dfunc("s:NetrwClearExplore()")
5690 2match none
5691 if exists("s:explore_match") |unlet s:explore_match |endif
5692 if exists("s:explore_indx") |unlet s:explore_indx |endif
5693 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5694 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5695 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5696 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5697 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5698 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5699 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5700" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005701" call Dret("s:NetrwClearExplore")
5702endfun
5703
5704" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005705" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5706fun! s:NetrwEditBuf(bufnum)
5707" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5708 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5709" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5710 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5711 else
5712" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005713 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005714 endif
5715" call Dret("s:NetrwEditBuf")
5716endfun
5717
5718" ---------------------------------------------------------------------
5719" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5720" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5721fun! s:NetrwEditFile(cmd,opt,fname)
5722" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5723 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5724" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5725 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5726 else
5727" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005728 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5729 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5730 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005731 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5732 endif
5733" call Dret("s:NetrwEditFile")
5734endfun
5735
5736" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005737" s:NetrwExploreListUniq: {{{2
5738fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005739" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005740
5741 " this assumes that the list is already sorted
5742 let newexplist= []
5743 for member in a:explist
5744 if !exists("uniqmember") || member != uniqmember
5745 let uniqmember = member
5746 let newexplist = newexplist + [ member ]
5747 endif
5748 endfor
5749
Bram Moolenaar15146672011-10-20 22:22:38 +02005750" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005751 return newexplist
5752endfun
5753
5754" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005755" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5756fun! s:NetrwForceChgDir(islocal,newdir)
5757" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005758 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005759 if a:newdir !~ '/$'
5760 " ok, looks like force is needed to get directory-style treatment
5761 if a:newdir =~ '@$'
5762 let newdir= substitute(a:newdir,'@$','/','')
5763 elseif a:newdir =~ '[*=|\\]$'
5764 let newdir= substitute(a:newdir,'.$','/','')
5765 else
5766 let newdir= a:newdir.'/'
5767 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005768" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005769 else
5770 " should already be getting treatment as a directory
5771 let newdir= a:newdir
5772 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005773 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005774 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005775 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005776" call Dret("s:NetrwForceChgDir")
5777endfun
5778
5779" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005780" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005781" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5782" expr : this is the expression to follow the directory. Will use s:ComposePath()
5783" pare =1: remove the current directory from the resulting glob() filelist
5784" =0: leave the current directory in the resulting glob() filelist
5785fun! s:NetrwGlob(direntry,expr,pare)
5786" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005787 if netrw#CheckIfRemote()
5788 keepalt 1sp
5789 keepalt enew
5790 let keep_liststyle = w:netrw_liststyle
5791 let w:netrw_liststyle = s:THINLIST
5792 if s:NetrwRemoteListing() == 0
5793 keepj keepalt %s@/@@
5794 let filelist= getline(1,$)
5795 q!
5796 else
5797 " remote listing error -- leave treedict unchanged
5798 let filelist= w:netrw_treedict[a:direntry]
5799 endif
5800 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005801 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5802 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5803 if a:pare
5804 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5805 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005806 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005807 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5808 if a:pare
5809 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5810 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005811 endif
5812" call Dret("s:NetrwGlob ".string(filelist))
5813 return filelist
5814endfun
5815
5816" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005817" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5818fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005819" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005820 if a:newfile =~ '[/@*=|\\]$'
5821 let newfile= substitute(a:newfile,'.$','','')
5822 else
5823 let newfile= a:newfile
5824 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005825 if a:islocal
5826 call s:NetrwBrowseChgDir(a:islocal,newfile)
5827 else
5828 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5829 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005830" call Dret("s:NetrwForceFile")
5831endfun
5832
5833" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005834" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5835" and switches the hiding mode. The actual hiding is done by
5836" s:NetrwListHide().
5837" g:netrw_hide= 0: show all
5838" 1: show not-hidden files
5839" 2: show hidden files only
5840fun! s:NetrwHide(islocal)
5841" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005842 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005843 let svpos= winsaveview()
5844" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005845
5846 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005847" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5848" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005849
5850 " hide the files in the markfile list
5851 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852" 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 +00005853 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5854 " remove fname from hiding list
5855 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5856 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5857 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005858" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859 else
5860 " append fname to hiding list
5861 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5862 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5863 else
5864 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5865 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005866" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005867 endif
5868 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005869 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870 let g:netrw_hide= 1
5871
5872 else
5873
5874 " switch between show-all/show-not-hidden/show-hidden
5875 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005876 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005879 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880" call Dret("NetrwHide")
5881 return
5882 endif
5883 endif
5884
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005885 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005886" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5887 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005888 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005889" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005890endfun
5891
5892" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005893" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5894fun! s:NetrwHideEdit(islocal)
5895" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5896
5897 let ykeep= @@
5898 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005899 let svpos= winsaveview()
5900" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005901
5902 " get new hiding list from user
5903 call inputsave()
5904 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5905 call inputrestore()
5906 let g:netrw_list_hide= newhide
5907" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5908
5909 " refresh the listing
5910 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5911
5912 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005913" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5914 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005915 let @@= ykeep
5916
5917" call Dret("NetrwHideEdit")
5918endfun
5919
5920" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921" s:NetrwHidden: invoked by "gh" {{{2
5922fun! s:NetrwHidden(islocal)
5923" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005924 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005925 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005926 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005927" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928
5929 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005930 " remove .file pattern from hiding list
5931" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005932 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005933 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005934" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005935 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5936 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005937" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5939 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005940 if g:netrw_list_hide =~ '^,'
5941 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5942 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943
5944 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005945 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005946" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5947 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005948 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949" call Dret("s:NetrwHidden")
5950endfun
5951
5952" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005953" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5954fun! s:NetrwHome()
5955 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005956 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005957 else
5958 " go to vim plugin home
5959 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005960 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005961 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005962 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005963 let home= basehome."/.vim"
5964 break
5965 endif
5966 endfor
5967 if home == ""
5968 " just pick the first directory
5969 let home= substitute(&rtp,',.*$','','')
5970 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005971 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005972 let home= substitute(home,'/','\\','g')
5973 endif
5974 endif
5975 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005976 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005977" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005978 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005979" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005981 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983 call mkdir(home)
5984 endif
5985 endif
5986 let g:netrw_home= home
5987 return home
5988endfun
5989
5990" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005991" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5992fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005993 if exists("s:netrwdrag")
5994 return
5995 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005996 if &ft != "netrw"
5997 return
5998 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005999" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006000
Bram Moolenaar97d62492012-11-15 21:28:22 +01006001 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006002 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006003 while getchar(0) != 0
6004 "clear the input stream
6005 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006006 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006007 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006008 let mouse_lnum = v:mouse_lnum
6009 let wlastline = line('w$')
6010 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006011" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6012" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006013 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6014 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006015 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006016" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6017 return
6018 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006019 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006020 " 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 +01006021 " without this test when its disabled.
6022 " 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 +01006023" 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 +01006024 if v:mouse_col > virtcol('.')
6025 let @@= ykeep
6026" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6027 return
6028 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006029
Bram Moolenaar446cb832008-06-24 21:56:24 +00006030 if a:islocal
6031 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006032 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006033 endif
6034 else
6035 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006036 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006037 endif
6038 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006039 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006040" call Dret("s:NetrwLeftmouse")
6041endfun
6042
6043" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006044" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6045fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006046 if &ft != "netrw"
6047 return
6048 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006049" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6050 call s:NetrwMarkFileTgt(a:islocal)
6051" call Dret("s:NetrwCLeftmouse")
6052endfun
6053
6054" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006055" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6056" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006057" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006058" a:islocal=2 : <c-r> used, remote
6059" a:islocal=3 : <c-r> used, local
6060fun! s:NetrwServerEdit(islocal,fname)
6061" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6062 let islocal = a:islocal%2 " =0: remote =1: local
6063 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006064" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006065
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006068 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006069" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006071 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6073 unlet s:netrw_browse_split_{winnr()}
6074 endif
6075 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6076" call Dret("s:NetrwServerEdit")
6077 return
6078 endif
6079
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006080" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006081 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083
6084 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 let srvrname = g:netrw_browse_split[0]
6087 let tabnum = g:netrw_browse_split[1]
6088 let winnum = g:netrw_browse_split[2]
6089
6090 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006091" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006092
6093 if !ctrlr
6094 " user must have closed the server window and the user did not use <c-r>, but
6095 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006098 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099 endif
6100 let g:netrw_browse_split= 0
6101 if exists("s:netrw_browse_split_".winnr())
6102 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6103 endif
6104 call s:NetrwBrowseChgDir(islocal,a:fname)
6105" call Dret("s:NetrwServerEdit")
6106 return
6107
6108 elseif has("win32") && executable("start")
6109 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006111 call system("start gvim --servername ".srvrname)
6112
6113 else
6114 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 call system("gvim --servername ".srvrname)
6117 endif
6118 endif
6119
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6122 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124
6125 else
6126
6127 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6128
6129 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006132 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006133 endif
6134 let g:netrw_browse_split= 0
6135 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6136" call Dret("s:NetrwServerEdit")
6137 return
6138
6139 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006140" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006141 if has("win32") && executable("start")
6142 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006143" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006144 call system("start gvim --servername ".g:netrw_servername)
6145 else
6146 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006147" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006148 call system("gvim --servername ".g:netrw_servername)
6149 endif
6150 endif
6151 endif
6152
6153 while 1
6154 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006155" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6156 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006157 break
6158 catch /^Vim\%((\a\+)\)\=:E241/
6159 sleep 200m
6160 endtry
6161 endwhile
6162
6163 if exists("g:netrw_browse_split")
6164 if type(g:netrw_browse_split) != 3
6165 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6166 endif
6167 unlet g:netrw_browse_split
6168 endif
6169 let g:netrw_browse_split= [g:netrw_servername,1,1]
6170 endif
6171
6172 else
6173 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6174 endif
6175
6176" call Dret("s:NetrwServerEdit")
6177endfun
6178
6179" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006180" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6181fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006182 if &ft != "netrw"
6183 return
6184 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006185" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006186
Bram Moolenaar8d043172014-01-23 14:24:41 +01006187 let s:ngw= s:NetrwGetWord()
6188 call s:NetrwMarkFile(a:islocal,s:ngw)
6189
6190" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006191endfun
6192
6193" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006194" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6195" Used to mark multiple files.
6196fun! s:NetrwSLeftdrag(islocal)
6197" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6198 if !exists("s:netrwdrag")
6199 let s:netrwdrag = winnr()
6200 if a:islocal
6201 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006202 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006203 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006204 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006205 endif
6206 let ngw = s:NetrwGetWord()
6207 if !exists("s:ngw") || s:ngw != ngw
6208 call s:NetrwMarkFile(a:islocal,ngw)
6209 endif
6210 let s:ngw= ngw
6211" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6212endfun
6213
6214" ---------------------------------------------------------------------
6215" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6216fun! s:NetrwSLeftrelease(islocal)
6217" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6218 if exists("s:netrwdrag")
6219 nunmap <s-leftrelease>
6220 let ngw = s:NetrwGetWord()
6221 if !exists("s:ngw") || s:ngw != ngw
6222 call s:NetrwMarkFile(a:islocal,ngw)
6223 endif
6224 if exists("s:ngw")
6225 unlet s:ngw
6226 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006227 unlet s:netrwdrag
6228 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006229" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006230endfun
6231
6232" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006233" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6234" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006236" 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 +02006237" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006238 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006239
6240 " 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 +02006241 " How-it-works: take the hiding command, convert it into a range.
6242 " Duplicate characters don't matter.
6243 " Remove all such characters from the '/~@#...890' string.
6244 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006245" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006246 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006247 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006248" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006249
6250 while listhide != ""
6251 if listhide =~ ','
6252 let hide = substitute(listhide,',.*$','','e')
6253 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6254 else
6255 let hide = listhide
6256 let listhide = ""
6257 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006258" 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 +01006259 if g:netrw_sort_by =~ '^[ts]'
6260 if hide =~ '^\^'
6261" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6262 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6263 elseif hide =~ '^\\(\^'
6264 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6265 endif
6266" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6267 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006268
6269 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006270" 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 +00006271 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006272" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006273 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006275" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006276 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006278" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006282 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006283" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006284 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 endif
6287
Bram Moolenaaradc21822011-04-01 18:03:16 +02006288 " remove any blank lines that have somehow remained.
6289 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006290 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006291
Bram Moolenaar97d62492012-11-15 21:28:22 +01006292 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006293" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294endfun
6295
6296" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006300" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301
Bram Moolenaar97d62492012-11-15 21:28:22 +01006302 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303 " get name of new directory from user. A bare <CR> will skip.
6304 " if its currently a directory, also request will be skipped, but with
6305 " a message.
6306 call inputsave()
6307 let newdirname= input("Please give directory name: ")
6308 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006309" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006310
6311 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006312 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006313" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006314 return
6315 endif
6316
6317 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006318" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319
6320 " Local mkdir:
6321 " sanity checks
6322 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006323" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6324 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006326 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006328 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006329" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006330 return
6331 endif
6332 if s:FileReadable(fullnewdir)
6333 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006334 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006336 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006337" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338 return
6339 endif
6340
6341 " requested new local directory is neither a pre-existing file or
6342 " directory, so make it!
6343 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006344 if has("unix")
6345 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6346 else
6347 call mkdir(fullnewdir,"p")
6348 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006349 else
6350 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006351 if s:NetrwLcd(b:netrw_curdir)
6352" call Dret("s:NetrwMakeDir : lcd failure")
6353 return
6354 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006355" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006356 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006357 if v:shell_error != 0
6358 let @@= ykeep
6359 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 +01006360" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006361 return
6362 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006364" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006365 if s:NetrwLcd(netrw_origdir)
6366" call Dret("s:NetrwBrowse : lcd failure")
6367 return
6368 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006369 endif
6370 endif
6371
6372 if v:shell_error == 0
6373 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006374" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006375 let svpos= winsaveview()
6376" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006377 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006378" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6379 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006380 elseif !exists("g:netrw_quiet")
6381 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6382 endif
6383" redraw!
6384
6385 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006386 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006387" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006388 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6389 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006390 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006391 if v:shell_error == 0
6392 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006393 let svpos= winsaveview()
6394" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006395 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006396" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6397 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006399 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006400 endif
6401" redraw!
6402
6403 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006404 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006405 let svpos= winsaveview()
6406" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006407" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006408 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006409" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 let remotepath= b:netrw_fname
6411 else
6412 let remotepath= ""
6413 endif
6414 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006415 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006416" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6417 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006418
Bram Moolenaar446cb832008-06-24 21:56:24 +00006419 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006421 let svpos= winsaveview()
6422" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006423" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006424 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 let remotepath= b:netrw_fname
6427 else
6428 let remotepath= ""
6429 endif
6430 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006431 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006432" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6433 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006434 endif
6435
Bram Moolenaar97d62492012-11-15 21:28:22 +01006436 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006437" call Dret("s:NetrwMakeDir")
6438endfun
6439
6440" ---------------------------------------------------------------------
6441" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6442fun! s:TreeSqueezeDir(islocal)
6443" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6444 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6445 " its a tree-listing style
6446 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006447 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006448 let depth = strchars(substitute(curdepth,' ','','g'))
6449 let srch = -1
6450" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6451" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006452" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006453" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6454 if depth >= 2
6455 NetrwKeepj norm! 0
6456 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6457 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6458" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6459" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6460 elseif depth == 1
6461 NetrwKeepj norm! 0
6462 let treedepthchr= substitute(s:treedepthstring,' ','','')
6463 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6464" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6465 endif
6466 if srch > 0
6467" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6468 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6469 exe srch
6470 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006471 endif
6472" call Dret("s:TreeSqueezeDir")
6473endfun
6474
6475" ---------------------------------------------------------------------
6476" s:NetrwMaps: {{{2
6477fun! s:NetrwMaps(islocal)
6478" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6479
Bram Moolenaar85850f32019-07-19 22:05:51 +02006480 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006481 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006482" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006483 if !hasmapto("<Plug>NetrwReturn")
6484 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6487 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006488" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6490 endif
6491 endif
6492 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006493" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 endif
6495
Bram Moolenaar85850f32019-07-19 22:05:51 +02006496 " generate default <Plug> maps {{{3
6497 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006498 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006499 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6500 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6501 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6502 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6503 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6504 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6505 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6506 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6507 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6508 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6509" ---------------------------------------------------------------------
6510" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6511" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6512" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6513" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6514" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6515" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6516" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6517" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6518" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6519" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6520" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6521" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6522" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6523" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6524" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6525" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6526" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6527" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6528" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6529" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6530" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6531" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6532" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6533" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6534" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6535" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6536" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6537" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6538" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6539" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6540" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6541" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6542" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6543" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6544" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6545" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6546" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6547" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6548" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6549" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6550" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6551" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6552" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6553" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6554" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6555" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6556" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6557
Bram Moolenaara6878372014-03-22 21:02:50 +01006558 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006559" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006560 " local normal-mode maps {{{3
6561 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6562 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6563 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6565 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6566 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6572" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006573 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6574 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6575 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006576 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006577 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006578 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6579 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6580 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6581 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006582 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6583 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6584 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6586 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6588 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6589 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6591 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006595 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006596 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6600 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006602 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006604 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6605 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006606 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6607 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6608 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6612 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006613 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6616 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6617 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006618 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6619 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006620
6621 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 +01006622 if !hasmapto('<Plug>NetrwHideEdit')
6623 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006624 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006625 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006626 if !hasmapto('<Plug>NetrwRefresh')
6627 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006629 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 +01006630 if s:didstarstar || !mapcheck("<s-down>","n")
6631 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 endif
6633 if s:didstarstar || !mapcheck("<s-up>","n")
6634 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006635 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006636 if !hasmapto('<Plug>NetrwTreeSqueeze')
6637 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006638 endif
6639 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6641 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006642 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6643 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6644 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6645 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6646 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6647 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6648 imap <buffer> <leftmouse> <Plug>ILeftmouse
6649 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006650 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6651 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6652 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6653 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6654 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006655 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006656 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6657 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006659 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6660 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6661 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6662 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6663 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6664 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6665 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006666 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6667
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006668 " support user-specified maps
6669 call netrw#UserMaps(1)
6670
Bram Moolenaar85850f32019-07-19 22:05:51 +02006671 else
6672 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006674 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006675 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6676 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6677 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6678 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6679 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6680 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6686" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006687 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6688 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6689 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6690 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6691 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6692 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6693 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6694 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006696 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6699 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6701 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6702 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6704 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006708 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006709 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006710 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6714 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006715 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6718 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006719 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006720 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6721 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006722 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006723 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 +01006724 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6726 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6727 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6728 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6729 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6730 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6731 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6732 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006733 if !hasmapto('<Plug>NetrwHideEdit')
6734 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 endif
6736 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6737 if !hasmapto('<Plug>NetrwRefresh')
6738 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006739 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006740 if !hasmapto('<Plug>NetrwTreeSqueeze')
6741 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006742 endif
6743 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006744
6745 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006746 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006747
6748 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6749 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006751 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006753 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006755 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006757 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006759 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6761 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6762 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006764 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006765 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6766 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006767 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6769 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6770 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6771 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6772 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6773 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006775 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006776
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006777 " support user-specified maps
6778 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006779 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006780
6781" call Dret("s:NetrwMaps")
6782endfun
6783
6784" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006785" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006786" If -buffer, the command is only available from within netrw buffers
6787" Otherwise, the command is available from any window, so long as netrw
6788" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006789fun! s:NetrwCommands(islocal)
6790" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6791
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006792 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6793 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006794 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 +01006795 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006796 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006797 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006798 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006799 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006800 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006801
6802" call Dret("s:NetrwCommands")
6803endfun
6804
6805" ---------------------------------------------------------------------
6806" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6807" glob()ing only works with local files
6808fun! s:NetrwMarkFiles(islocal,...)
6809" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006810 let curdir = s:NetrwGetCurdir(a:islocal)
6811 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 while i <= a:0
6813 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006814 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006815 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006816 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006817 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006819 else
6820 let mffiles= [a:{i}]
6821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006822" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006823 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006825 call s:NetrwMarkFile(a:islocal,mffile)
6826 endfor
6827 let i= i + 1
6828 endwhile
6829" call Dret("s:NetrwMarkFiles")
6830endfun
6831
6832" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006833" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006834fun! s:NetrwMarkTarget(...)
6835" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6836 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006837 let curdir = s:NetrwGetCurdir(1)
6838 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006839 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6841 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006842 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006843" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6846 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006847 let svpos = winsaveview()
6848" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006850" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6851 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006852" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006853endfun
6854
6855" ---------------------------------------------------------------------
6856" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6857" mark and unmark files. If a markfile list exists,
6858" then the rename and delete functions will use it instead
6859" of whatever may happen to be under the cursor at that
6860" moment. When the mouse and gui are available,
6861" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006862"
6863" Creates two lists
6864" s:netrwmarkfilelist -- holds complete paths to all marked files
6865" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6866"
6867" Creates a marked file match string
6868" s:netrwmarfilemtch_# -- used with 2match to display marked files
6869"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006870" Creates a buffer version of islocal
6871" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872fun! s:NetrwMarkFile(islocal,fname)
6873" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006874" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006875
6876 " sanity check
6877 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006878" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006879 return
6880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006881 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006882
Bram Moolenaar97d62492012-11-15 21:28:22 +01006883 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006884 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006885 if a:fname =~ '^\a'
6886 let leader= '\<'
6887 else
6888 let leader= ''
6889 endif
6890 if a:fname =~ '\a$'
6891 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6892 else
6893 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6894 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006895
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006896 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006897 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6899" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6900" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006901 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902
6903 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006904 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006905" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006906 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006907 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908
6909 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006910 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6913 if s:netrwmarkfilelist_{curbufnr} == []
6914 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 call s:NetrwUnmarkList(curbufnr,curdir)
6917 else
6918 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006919" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006920 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006921 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 for fname in s:netrwmarkfilelist_{curbufnr}
6923 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006924 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 endif
6928 let first= 0
6929 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006931 endif
6932 endif
6933
6934 else
6935 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006937
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006938" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006939 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6941" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
6943 " build initial markfile matching pattern
6944 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006945 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006947 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006949" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 endif
6951
6952 " handle global markfilelist
6953 if exists("s:netrwmarkfilelist")
6954 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6955 if index(s:netrwmarkfilelist,dname) == -1
6956 " append new filename to global markfilelist
6957 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006958" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 else
6960 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006961" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6962" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006964" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 unlet s:netrwmarkfilelist
6968 endif
6969 endif
6970 else
6971 " initialize new global-directory markfilelist
6972 let s:netrwmarkfilelist= []
6973 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006974" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006975 endif
6976
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006977 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006978 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6979 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6980" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6981 if exists("g:did_drchip_netrwlist_syntax")
6982 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6983 endif
6984 else
6985" " call Decho("2match none",'~'.expand("<slnum>"))
6986 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006987 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006988 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006989 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006990" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6991" 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 +00006992endfun
6993
6994" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006995" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6996" mA: move the argument list to marked file list (tomflist=1)
6997" Uses the global marked file list
6998fun! s:NetrwMarkFileArgList(islocal,tomflist)
6999" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7000
7001 let svpos = winsaveview()
7002" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7003 let curdir = s:NetrwGetCurdir(a:islocal)
7004 let curbufnr = bufnr("%")
7005
7006 if a:tomflist
7007 " mA: move argument list to marked file list
7008 while argc()
7009 let fname= argv(0)
7010" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7011 exe "argdel ".fnameescape(fname)
7012 call s:NetrwMarkFile(a:islocal,fname)
7013 endwhile
7014
7015 else
7016 " ma: move marked file list to argument list
7017 if exists("s:netrwmarkfilelist")
7018
7019 " for every filename in the marked list
7020 for fname in s:netrwmarkfilelist
7021" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7022 exe "argadd ".fnameescape(fname)
7023 endfor " for every file in the marked list
7024
7025 " unmark list and refresh
7026 call s:NetrwUnmarkList(curbufnr,curdir)
7027 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7028" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7029 NetrwKeepj call winrestview(svpos)
7030 endif
7031 endif
7032
7033" call Dret("s:NetrwMarkFileArgList")
7034endfun
7035
7036" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007037" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7038" compress/decompress files using the programs
7039" in g:netrw_compress and g:netrw_uncompress,
7040" using g:netrw_compress_suffix to know which to
7041" do. By default:
7042" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007043" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007044fun! s:NetrwMarkFileCompress(islocal)
7045" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007046 let svpos = winsaveview()
7047" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007048 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007049 let curbufnr = bufnr("%")
7050
Bram Moolenaarff034192013-04-24 18:51:19 +02007051 " sanity check
7052 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007053 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007054" call Dret("s:NetrwMarkFileCompress")
7055 return
7056 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007057" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007058
Bram Moolenaar446cb832008-06-24 21:56:24 +00007059 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007060
7061 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007062 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007063 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007064" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007065 if exists("g:netrw_decompress['".sfx."']")
7066 " fname has a suffix indicating that its compressed; apply associated decompression routine
7067 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007068" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007069 let exe= netrw#WinPath(exe)
7070 if a:islocal
7071 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007072 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007073 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007074 call system(exe." ".fname)
7075 if v:shell_error
7076 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007077 endif
7078 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7080 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007081 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007082
Bram Moolenaarff034192013-04-24 18:51:19 +02007083 endif
7084 unlet sfx
7085
Bram Moolenaar446cb832008-06-24 21:56:24 +00007086 if exists("exe")
7087 unlet exe
7088 elseif a:islocal
7089 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007090 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007091 if v:shell_error
7092 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 else
7095 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007096 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007098 endfor " for every file in the marked list
7099
Bram Moolenaar446cb832008-06-24 21:56:24 +00007100 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007101 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007102" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7103 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007104 endif
7105" call Dret("s:NetrwMarkFileCompress")
7106endfun
7107
7108" ---------------------------------------------------------------------
7109" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7110" If no marked files, then set up directory as the
7111" target. Currently does not support copying entire
7112" directories. Uses the local-buffer marked file list.
7113" Returns 1=success (used by NetrwMarkFileMove())
7114" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007115fun! s:NetrwMarkFileCopy(islocal,...)
7116" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7117
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007118 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007119 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007120 if b:netrw_curdir !~ '/$'
7121 if !exists("b:netrw_curdir")
7122 let b:netrw_curdir= curdir
7123 endif
7124 let b:netrw_curdir= b:netrw_curdir."/"
7125 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007126
Bram Moolenaarff034192013-04-24 18:51:19 +02007127 " sanity check
7128 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007129 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007130" call Dret("s:NetrwMarkFileCopy")
7131 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007133" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007134
Bram Moolenaar446cb832008-06-24 21:56:24 +00007135 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007136 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137" call Dret("s:NetrwMarkFileCopy 0")
7138 return 0
7139 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007140" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007141
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007142 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007143 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007144" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007145 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007146 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7147" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7148 return
7149 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007150
7151 " copy marked files while within the same directory (ie. allow renaming)
7152 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7153 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7154 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007155" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007156 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007157 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7158 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007159" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007160 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007161 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 let oldname = a:1
7163 else
7164 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007165" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007166 let s:recursive= 1
7167 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7168 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7169 if ret == 0
7170 break
7171 endif
7172 endfor
7173 unlet s:recursive
7174 call s:NetrwUnmarkList(curbufnr,curdir)
7175" call Dret("s:NetrwMarkFileCopy ".ret)
7176 return ret
7177 endif
7178
7179 call inputsave()
7180 let newname= input("Copy ".oldname." to : ",oldname,"file")
7181 call inputrestore()
7182 if newname == ""
7183" call Dret("s:NetrwMarkFileCopy 0")
7184 return 0
7185 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007186 let args= s:ShellEscape(oldname)
7187 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007188 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007189 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7190 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007191 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007192 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007193 let args= substitute(args,'/','\\','g')
7194 let tgt = substitute(tgt, '/','\\','g')
7195 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007196 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7197 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7198 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7199 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7200" call Decho("args <".args.">",'~'.expand("<slnum>"))
7201" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007202 if isdirectory(s:NetrwFile(args))
7203" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007204 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007206 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007207 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7208 " contents to a target. One must append the source directory name to the target to get xcopy to
7209 " do the right thing.
7210 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007211" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007212 endif
7213 else
7214 let copycmd= g:netrw_localcopycmd
7215 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007216 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 let copycmd = substitute(copycmd,'\s.*$','','')
7218 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007219 let copycmd = netrw#WinPath(copycmd).copycmdargs
7220 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007221 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007222 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007223" call Decho("args <".args.">",'~'.expand("<slnum>"))
7224" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7225" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7226" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007227 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007228 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007229 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007230 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 +01007231 else
7232 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7233 endif
7234" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007235 return 0
7236 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007237
7238 elseif a:islocal && !s:netrwmftgt_islocal
7239 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007240" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007241 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
7243 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007244 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247
7248 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007249 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007251 let curdir = getcwd()
7252 let tmpdir = s:GetTempfile("")
7253 if tmpdir !~ '/'
7254 let tmpdir= curdir."/".tmpdir
7255 endif
7256 if exists("*mkdir")
7257 call mkdir(tmpdir)
7258 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007259 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007260 if v:shell_error != 0
7261 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 +01007262" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007263 return
7264 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007265 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007267 if s:NetrwLcd(tmpdir)
7268" call Dret("s:NetrwMarkFileCopy : lcd failure")
7269 return
7270 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007271 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007272 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007273 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007274 if getcwd() == tmpdir
7275 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007277 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007278 if s:NetrwLcd(curdir)
7279" call Dret("s:NetrwMarkFileCopy : lcd failure")
7280 return
7281 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007282 if delete(tmpdir,"d")
7283 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007284 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007285 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007286 if s:NetrwLcd(curdir)
7287" call Dret("s:NetrwMarkFileCopy : lcd failure")
7288 return
7289 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 endif
7291 endif
7292 endif
7293
7294 " -------
7295 " cleanup
7296 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007297" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007298 " remove markings from local buffer
7299 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007300" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7301" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7302" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7303" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7304" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7305" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7306 if exists("s:recursive")
7307" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7308 else
7309" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007310 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007311 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007312 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007313 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007314 else
7315 " refresh local and targets for fast browsing
7316 if !exists("s:recursive")
7317 " remove markings from local buffer
7318" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7319 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7320 endif
7321
7322 " refresh buffers
7323 if s:netrwmftgt_islocal
7324" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7325 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7326 endif
7327 if a:islocal && s:netrwmftgt != curdir
7328" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7329 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7330 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007331 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007332
Bram Moolenaar446cb832008-06-24 21:56:24 +00007333" call Dret("s:NetrwMarkFileCopy 1")
7334 return 1
7335endfun
7336
7337" ---------------------------------------------------------------------
7338" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7339" invoke vim's diff mode on the marked files.
7340" Either two or three files can be so handled.
7341" Uses the global marked file list.
7342fun! s:NetrwMarkFileDiff(islocal)
7343" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7344 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007345
Bram Moolenaarff034192013-04-24 18:51:19 +02007346 " sanity check
7347 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007348 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007349" call Dret("s:NetrwMarkFileDiff")
7350 return
7351 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007352 let curdir= s:NetrwGetCurdir(a:islocal)
7353" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007354
Bram Moolenaara6878372014-03-22 21:02:50 +01007355 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007356 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007357 for fname in s:netrwmarkfilelist
7358 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007359 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007360" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007361 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 diffthis
7363 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007364 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007365" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367 diffthis
7368 else
7369 break
7370 endif
7371 endfor
7372 call s:NetrwUnmarkList(curbufnr,curdir)
7373 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007374
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375" call Dret("s:NetrwMarkFileDiff")
7376endfun
7377
7378" ---------------------------------------------------------------------
7379" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7380" Uses global markfilelist
7381fun! s:NetrwMarkFileEdit(islocal)
7382" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7383
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007384 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007385 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007386
7387 " sanity check
7388 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007389 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007390" call Dret("s:NetrwMarkFileEdit")
7391 return
7392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007394
Bram Moolenaar446cb832008-06-24 21:56:24 +00007395 if exists("s:netrwmarkfilelist_{curbufnr}")
7396 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007397 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007398 " unmark markedfile list
7399" call s:NetrwUnmarkList(curbufnr,curdir)
7400 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007401" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007402 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007404 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007405
Bram Moolenaar446cb832008-06-24 21:56:24 +00007406" call Dret("s:NetrwMarkFileEdit")
7407endfun
7408
7409" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007410" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007411fun! s:NetrwMarkFileQFEL(islocal,qfel)
7412" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7413 call s:NetrwUnmarkAll()
7414 let curbufnr= bufnr("%")
7415
7416 if !empty(a:qfel)
7417 for entry in a:qfel
7418 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007419" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007420 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007422 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7423 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7424 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7425 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007427 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7428 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007429" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007430 endif
7431 endfor
7432 echo "(use me to edit marked files)"
7433 else
7434 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7435 endif
7436
7437" call Dret("s:NetrwMarkFileQFEL")
7438endfun
7439
7440" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007441" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7442" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7443" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7444fun! s:NetrwMarkFileExe(islocal,enbloc)
7445" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007446 let svpos = winsaveview()
7447" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007448 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 let curbufnr = bufnr("%")
7450
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007451 if a:enbloc == 0
7452 " individually apply command to files, one at a time
7453 " sanity check
7454 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7455 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7456" call Dret("s:NetrwMarkFileExe")
7457 return
7458 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007460
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007461 if exists("s:netrwmarkfilelist_{curbufnr}")
7462 " get the command
7463 call inputsave()
7464 let cmd= input("Enter command: ","","file")
7465 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007466" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 if cmd == ""
7468" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7469 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007470 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007471
7472 " apply command to marked files, individually. Substitute: filename -> %
7473 " If no %, then append a space and the filename to the command
7474 for fname in s:netrwmarkfilelist_{curbufnr}
7475 if a:islocal
7476 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007477 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007478 endif
7479 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007480 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481 endif
7482 if cmd =~ '%'
7483 let xcmd= substitute(cmd,'%',fname,'g')
7484 else
7485 let xcmd= cmd.' '.fname
7486 endif
7487 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007488" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489 let ret= system(xcmd)
7490 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007491" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007492 let ret= s:RemoteSystem(xcmd)
7493 endif
7494 if v:shell_error < 0
7495 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7496 break
7497 else
7498 echo ret
7499 endif
7500 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007501
7502 " unmark marked file list
7503 call s:NetrwUnmarkList(curbufnr,curdir)
7504
7505 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007506 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007507" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7508 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007509 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512
7513 else " apply command to global list of files, en bloc
7514
7515 call inputsave()
7516 let cmd= input("Enter command: ","","file")
7517 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007518" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007519 if cmd == ""
7520" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7521 return
7522 endif
7523 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007524 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007525 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007526 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527 endif
7528 if a:islocal
7529 call system(cmd)
7530 if v:shell_error < 0
7531 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7532 endif
7533 else
7534 let ret= s:RemoteSystem(cmd)
7535 endif
7536 call s:NetrwUnmarkAll()
7537
7538 " refresh the listing
7539 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007540" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7541 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007542
7543 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007544
Bram Moolenaar446cb832008-06-24 21:56:24 +00007545" call Dret("s:NetrwMarkFileExe")
7546endfun
7547
7548" ---------------------------------------------------------------------
7549" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7550" as the marked file(s) (toggles suffix presence)
7551" Uses the local marked file list.
7552fun! s:NetrwMarkHideSfx(islocal)
7553" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007554 let svpos = winsaveview()
7555" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007556 let curbufnr = bufnr("%")
7557
7558 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7559 if exists("s:netrwmarkfilelist_{curbufnr}")
7560
7561 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007562" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007563 " construct suffix pattern
7564 if fname =~ '\.'
7565 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7566 else
7567 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7568 endif
7569 " determine if its in the hiding list or not
7570 let inhidelist= 0
7571 if g:netrw_list_hide != ""
7572 let itemnum = 0
7573 let hidelist= split(g:netrw_list_hide,',')
7574 for hidepat in hidelist
7575 if sfxpat == hidepat
7576 let inhidelist= 1
7577 break
7578 endif
7579 let itemnum= itemnum + 1
7580 endfor
7581 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007582" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007583 if inhidelist
7584 " remove sfxpat from list
7585 call remove(hidelist,itemnum)
7586 let g:netrw_list_hide= join(hidelist,",")
7587 elseif g:netrw_list_hide != ""
7588 " append sfxpat to non-empty list
7589 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7590 else
7591 " set hiding list to sfxpat
7592 let g:netrw_list_hide= sfxpat
7593 endif
7594 endfor
7595
7596 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007597 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007598" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7599 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007600 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007601 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 endif
7603
7604" call Dret("s:NetrwMarkHideSfx")
7605endfun
7606
7607" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007608" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007609" Uses the local marked-file list.
7610fun! s:NetrwMarkFileVimCmd(islocal)
7611" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007612 let svpos = winsaveview()
7613" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007615 let curbufnr = bufnr("%")
7616
Bram Moolenaarff034192013-04-24 18:51:19 +02007617 " sanity check
7618 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007619 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007620" call Dret("s:NetrwMarkFileVimCmd")
7621 return
7622 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007623" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007624
Bram Moolenaar15146672011-10-20 22:22:38 +02007625 if exists("s:netrwmarkfilelist_{curbufnr}")
7626 " get the command
7627 call inputsave()
7628 let cmd= input("Enter vim command: ","","file")
7629 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007630" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007631 if cmd == ""
7632" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7633 return
7634 endif
7635
7636 " apply command to marked files. Substitute: filename -> %
7637 " If no %, then append a space and the filename to the command
7638 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007640 if a:islocal
7641 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007642 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007643" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007644 exe cmd
7645 exe "sil! keepalt wq!"
7646 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007647" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007648 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 endif
7650 endfor
7651
7652 " unmark marked file list
7653 call s:NetrwUnmarkList(curbufnr,curdir)
7654
7655 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007657" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7658 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007660 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007662
Bram Moolenaar15146672011-10-20 22:22:38 +02007663" call Dret("s:NetrwMarkFileVimCmd")
7664endfun
7665
7666" ---------------------------------------------------------------------
7667" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7668" as the marked file(s) (toggles suffix presence)
7669" Uses the local marked file list.
7670fun! s:NetrwMarkHideSfx(islocal)
7671" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007672 let svpos = winsaveview()
7673" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007674 let curbufnr = bufnr("%")
7675
7676 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7677 if exists("s:netrwmarkfilelist_{curbufnr}")
7678
7679 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007680" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007681 " construct suffix pattern
7682 if fname =~ '\.'
7683 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7684 else
7685 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7686 endif
7687 " determine if its in the hiding list or not
7688 let inhidelist= 0
7689 if g:netrw_list_hide != ""
7690 let itemnum = 0
7691 let hidelist= split(g:netrw_list_hide,',')
7692 for hidepat in hidelist
7693 if sfxpat == hidepat
7694 let inhidelist= 1
7695 break
7696 endif
7697 let itemnum= itemnum + 1
7698 endfor
7699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007701 if inhidelist
7702 " remove sfxpat from list
7703 call remove(hidelist,itemnum)
7704 let g:netrw_list_hide= join(hidelist,",")
7705 elseif g:netrw_list_hide != ""
7706 " append sfxpat to non-empty list
7707 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7708 else
7709 " set hiding list to sfxpat
7710 let g:netrw_list_hide= sfxpat
7711 endif
7712 endfor
7713
7714 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007715 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007716" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7717 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007718 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007719 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007720 endif
7721
7722" call Dret("s:NetrwMarkHideSfx")
7723endfun
7724
7725" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007726" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7727" Uses the global markfilelist
7728fun! s:NetrwMarkFileGrep(islocal)
7729" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007730 let svpos = winsaveview()
7731" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007732 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007733 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007734
7735 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007736" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007737 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007738" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007740 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007741" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007742 let netrwmarkfilelist= "*"
7743 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744
Bram Moolenaarff034192013-04-24 18:51:19 +02007745 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007746" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 call inputsave()
7748 let pat= input("Enter pattern: ","")
7749 call inputrestore()
7750 let patbang = ""
7751 if pat =~ '^!'
7752 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007753 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007754 endif
7755 if pat =~ '^\i'
7756 let pat = escape(pat,'/')
7757 let pat = '/'.pat.'/'
7758 else
7759 let nonisi = pat[0]
7760 endif
7761
7762 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007763" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007764 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007765 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007766 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007767 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007768" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7769 return
7770 endtry
7771 echo "(use :cn, :cp to navigate, :Rex to return)"
7772
7773 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007774" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7775 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007776
7777 if exists("nonisi")
7778 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007780 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007781 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007782 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007783 endif
7784
7785" call Dret("s:NetrwMarkFileGrep")
7786endfun
7787
7788" ---------------------------------------------------------------------
7789" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7790" uses the global marked file list
7791" s:netrwmfloc= 0: target directory is remote
7792" = 1: target directory is local
7793fun! s:NetrwMarkFileMove(islocal)
7794" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007795 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007796 let curbufnr = bufnr("%")
7797
7798 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007799 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007800 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801" call Dret("s:NetrwMarkFileMove")
7802 return
7803 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007804" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007805
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007807 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808" call Dret("s:NetrwMarkFileCopy 0")
7809 return 0
7810 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007812
7813 if a:islocal && s:netrwmftgt_islocal
7814 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815" call Decho("move from local to local",'~'.expand("<slnum>"))
7816" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007817 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007818 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7819" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7820 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007822 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007823" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007824 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007825 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007826" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007827 if g:netrw_localmovecmd =~ '\s'
7828 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7829 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7830 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007832 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007833 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007835 endif
7836 else
7837 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007838" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007839 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007840 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007841 if g:netrw_keepdir
7842 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7843 let fname= b:netrw_curdir."/".fname
7844 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007845 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007846 let fname= substitute(fname,'/','\\','g')
7847 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007848" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007849 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007850 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007851 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007852 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 +01007853 else
7854 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7855 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007856 break
7857 endif
7858 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007859
7860 elseif a:islocal && !s:netrwmftgt_islocal
7861 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007862" call Decho("move from local to remote",'~'.expand("<slnum>"))
7863" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007864 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007865 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007867 for fname in mflist
7868 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7869 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7870 endfor
7871 unlet mflist
7872
7873 elseif !a:islocal && s:netrwmftgt_islocal
7874 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007875" call Decho("move from remote to local",'~'.expand("<slnum>"))
7876" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007877 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007878 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007879" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880 for fname in mflist
7881 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7882 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7883 endfor
7884 unlet mflist
7885
7886 elseif !a:islocal && !s:netrwmftgt_islocal
7887 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7889" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007890 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007891 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007892" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007893 for fname in mflist
7894 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7895 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7896 endfor
7897 unlet mflist
7898 endif
7899
7900 " -------
7901 " cleanup
7902 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007903" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007904
7905 " remove markings from local buffer
7906 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7907
7908 " refresh buffers
7909 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007910" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007911 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912 endif
7913 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007915 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007916 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007917 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007919 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007920 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922" call Dret("s:NetrwMarkFileMove")
7923endfun
7924
7925" ---------------------------------------------------------------------
7926" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7927" using the hardcopy command. Local marked-file list only.
7928fun! s:NetrwMarkFilePrint(islocal)
7929" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7930 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007931
7932 " sanity check
7933 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007934 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007935" call Dret("s:NetrwMarkFilePrint")
7936 return
7937 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007938" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7939 let curdir= s:NetrwGetCurdir(a:islocal)
7940
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941 if exists("s:netrwmarkfilelist_{curbufnr}")
7942 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007943 call s:NetrwUnmarkList(curbufnr,curdir)
7944 for fname in netrwmarkfilelist
7945 if a:islocal
7946 if g:netrw_keepdir
7947 let fname= s:ComposePath(curdir,fname)
7948 endif
7949 else
7950 let fname= curdir.fname
7951 endif
7952 1split
7953 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007954" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007955 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957 hardcopy
7958 q
7959 endfor
7960 2match none
7961 endif
7962" call Dret("s:NetrwMarkFilePrint")
7963endfun
7964
7965" ---------------------------------------------------------------------
7966" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7967" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007968" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969fun! s:NetrwMarkFileRegexp(islocal)
7970" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7971
7972 " get the regular expression
7973 call inputsave()
7974 let regexp= input("Enter regexp: ","","file")
7975 call inputrestore()
7976
7977 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007978 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007979" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007980 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007981" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007982 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007983 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007984 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007985 else
7986 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007987 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990
7991 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007992 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007993 if fname =~ '^'.fnameescape(curdir)
7994" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7995 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7996 else
7997" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7998 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7999 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008000 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008001
8002 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008004
8005 " convert displayed listing into a filelist
8006 let eikeep = &ei
8007 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008008 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008009 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008010" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008011 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008012 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008013 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008014 sil NetrwKeepj norm! "ap
8015 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008018 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008020 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008021 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008023 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008024 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008026 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8027 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008028 call histdel("/",-1)
8029 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 endif
8031 " convert regexp into the more usual glob-style format
8032 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008033" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008034 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008035 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036 let filelist= getline(1,line("$"))
8037 q!
8038 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040 endfor
8041 unlet filelist
8042 let @a = areg
8043 let &ei = eikeep
8044 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008045 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046
8047" call Dret("s:NetrwMarkFileRegexp")
8048endfun
8049
8050" ---------------------------------------------------------------------
8051" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8052" Uses the local marked file list.
8053fun! s:NetrwMarkFileSource(islocal)
8054" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8055 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008056
8057 " sanity check
8058 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008059 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008060" call Dret("s:NetrwMarkFileSource")
8061 return
8062 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008063" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8064 let curdir= s:NetrwGetCurdir(a:islocal)
8065
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066 if exists("s:netrwmarkfilelist_{curbufnr}")
8067 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 call s:NetrwUnmarkList(curbufnr,curdir)
8069 for fname in netrwmarkfilelist
8070 if a:islocal
8071 if g:netrw_keepdir
8072 let fname= s:ComposePath(curdir,fname)
8073 endif
8074 else
8075 let fname= curdir.fname
8076 endif
8077 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008078" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008079 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008080 endfor
8081 2match none
8082 endif
8083" call Dret("s:NetrwMarkFileSource")
8084endfun
8085
8086" ---------------------------------------------------------------------
8087" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8088" Uses the global markfilelist
8089fun! s:NetrwMarkFileTag(islocal)
8090" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008091 let svpos = winsaveview()
8092" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008093 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008094 let curbufnr = bufnr("%")
8095
Bram Moolenaarff034192013-04-24 18:51:19 +02008096 " sanity check
8097 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008098 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008099" call Dret("s:NetrwMarkFileTag")
8100 return
8101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008102" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008103
Bram Moolenaar446cb832008-06-24 21:56:24 +00008104 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008105" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8106 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008107 call s:NetrwUnmarkAll()
8108
8109 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008110
8111" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8112 call system(g:netrw_ctags." ".netrwmarkfilelist)
8113 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8115 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008116
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008118 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008119 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008120 let curdir= b:netrw_curdir
8121 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008122 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008124" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008125 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008126 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127 wq!
8128 endif
8129 2match none
8130 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008131" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8132 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008133 endif
8134
8135" call Dret("s:NetrwMarkFileTag")
8136endfun
8137
8138" ---------------------------------------------------------------------
8139" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008140" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008141" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008143" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008144fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008145" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8146 let svpos = winsaveview()
8147" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008148 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 let hadtgt = exists("s:netrwmftgt")
8150 if !exists("w:netrw_bannercnt")
8151 let w:netrw_bannercnt= b:netrw_bannercnt
8152 endif
8153
8154 " set up target
8155 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008157 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8158 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008159" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008160 unlet s:netrwmftgt s:netrwmftgt_islocal
8161 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008162 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008163 endif
8164 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008165" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8166 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008167" call Dret("s:NetrwMarkFileTgt : removed target")
8168 return
8169 else
8170 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008172 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008173
8174 else
8175 " get word under cursor.
8176 " * If directory, use it for the target.
8177 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008178" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008179 let curword= s:NetrwGetWord()
8180 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008181 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008182 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 elseif !a:islocal && tgtdir =~ '/$'
8185 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 else
8188 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008189" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008190 endif
8191 endif
8192 if a:islocal
8193 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8194 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008195" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196 endif
8197 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008198 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8200 endif
8201 let s:netrwmftgt_islocal= a:islocal
8202
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 " need to do refresh so that the banner will be updated
8204 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008205 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008206" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008207 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008209" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008210 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8212 else
8213 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8214 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008215" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8216 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008218 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 endif
8220
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8222" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008223" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8224endfun
8225
8226" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8228fun! s:NetrwGetCurdir(islocal)
8229" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8230
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008231 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8233" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8234 elseif !exists("b:netrw_curdir")
8235 let b:netrw_curdir= getcwd()
8236" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8237 endif
8238
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008239" 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 +01008240 if b:netrw_curdir !~ '\<\a\{3,}://'
8241 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008242" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243 if g:netrw_keepdir == 0
8244 call s:NetrwLcd(curdir)
8245 endif
8246 endif
8247
8248" call Dret("s:NetrwGetCurdir <".curdir.">")
8249 return b:netrw_curdir
8250endfun
8251
8252" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008253" s:NetrwOpenFile: query user for a filename and open it {{{2
8254fun! s:NetrwOpenFile(islocal)
8255" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008256 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008257 call inputsave()
8258 let fname= input("Enter filename: ")
8259 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008260" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8261
8262 " determine if Lexplore is in use
8263 if exists("t:netrw_lexbufnr")
8264 " check if t:netrw_lexbufnr refers to a netrw window
8265" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8266 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8267 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8268" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8269 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8270 exe "NetrwKeepj e ".fnameescape(fname)
8271 let @@= ykeep
8272" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8273 endif
8274 endif
8275
8276 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008277 if fname !~ '[/\\]'
8278 if exists("b:netrw_curdir")
8279 if exists("g:netrw_quiet")
8280 let netrw_quiet_keep = g:netrw_quiet
8281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008282 let g:netrw_quiet = 1
8283 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008284 let s:rexposn_{bufnr("%")}= winsaveview()
8285" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008286 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008287 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008288 else
8289 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8290 endif
8291 if exists("netrw_quiet_keep")
8292 let g:netrw_quiet= netrw_quiet_keep
8293 else
8294 unlet g:netrw_quiet
8295 endif
8296 endif
8297 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008298 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008299 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008300 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008301" call Dret("s:NetrwOpenFile")
8302endfun
8303
8304" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008305" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8306" For the mapping to this function be made via
8307" netrwPlugin, you'll need to have had
8308" g:netrw_usetab set to non-zero.
8309fun! netrw#Shrink()
8310" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8311 let curwin = winnr()
8312 let wiwkeep = &wiw
8313 set wiw=1
8314
8315 if &ft == "netrw"
8316 if winwidth(0) > g:netrw_wiw
8317 let t:netrw_winwidth= winwidth(0)
8318 exe "vert resize ".g:netrw_wiw
8319 wincmd l
8320 if winnr() == curwin
8321 wincmd h
8322 endif
8323" call Decho("vert resize 0",'~'.expand("<slnum>"))
8324 else
8325 exe "vert resize ".t:netrw_winwidth
8326" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8327 endif
8328
8329 elseif exists("t:netrw_lexbufnr")
8330 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8331 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8332 let t:netrw_winwidth= winwidth(0)
8333 exe "vert resize ".g:netrw_wiw
8334 wincmd l
8335 if winnr() == curwin
8336 wincmd h
8337 endif
8338" call Decho("vert resize 0",'~'.expand("<slnum>"))
8339 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8340 exe "vert resize ".t:netrw_winwidth
8341" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8342 else
8343 call netrw#Lexplore(0,0)
8344 endif
8345
8346 else
8347 call netrw#Lexplore(0,0)
8348 endif
8349 let wiw= wiwkeep
8350
8351" call Dret("netrw#Shrink")
8352endfun
8353
8354" ---------------------------------------------------------------------
8355" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8356fun! s:NetSortSequence(islocal)
8357" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8358
8359 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008360 let svpos= winsaveview()
8361" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008362 call inputsave()
8363 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8364 call inputrestore()
8365
8366 " refresh the listing
8367 let g:netrw_sort_sequence= newsortseq
8368 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008369" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8370 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008371 let @@= ykeep
8372
8373" call Dret("NetSortSequence")
8374endfun
8375
8376" ---------------------------------------------------------------------
8377" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8378" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008379" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380fun! s:NetrwUnmarkList(curbufnr,curdir)
8381" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8382
8383 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008384 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8386 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8387 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8388 call remove(s:netrwmarkfilelist,idx) " remove from global list
8389 endfor
8390 if s:netrwmarkfilelist == []
8391 unlet s:netrwmarkfilelist
8392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008393
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394 " getting rid of the local marked-file lists is easy
8395 unlet s:netrwmarkfilelist_{a:curbufnr}
8396 endif
8397 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8398 unlet s:netrwmarkfilemtch_{a:curbufnr}
8399 endif
8400 2match none
8401" call Dret("s:NetrwUnmarkList")
8402endfun
8403
8404" ---------------------------------------------------------------------
8405" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8406fun! s:NetrwUnmarkAll()
8407" call Dfunc("s:NetrwUnmarkAll()")
8408 if exists("s:netrwmarkfilelist")
8409 unlet s:netrwmarkfilelist
8410 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008411 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008412 2match none
8413" call Dret("s:NetrwUnmarkAll")
8414endfun
8415
8416" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008417" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418fun! s:NetrwUnmarkAll2()
8419" call Dfunc("s:NetrwUnmarkAll2()")
8420 redir => netrwmarkfilelist_let
8421 let
8422 redir END
8423 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008424 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8426 for flist in netrwmarkfilelist_list
8427 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8428 unlet s:netrwmarkfilelist_{curbufnr}
8429 unlet s:netrwmarkfilemtch_{curbufnr}
8430 endfor
8431" call Dret("s:NetrwUnmarkAll2")
8432endfun
8433
8434" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008435" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8436"
8437" Marked files are in two types of lists:
8438" s:netrwmarkfilelist -- holds complete paths to all marked files
8439" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8440"
8441" Marked files suitable for use with 2match are in:
8442" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008443fun! s:NetrwUnMarkFile(islocal)
8444" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008445 let svpos = winsaveview()
8446" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 let curbufnr = bufnr("%")
8448
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008449 " unmark marked file list
8450 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8451 if exists("s:netrwmarkfilelist")
8452" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454 endif
8455
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008456 let ibuf= 1
8457 while ibuf < bufnr("$")
8458 if exists("s:netrwmarkfilelist_".ibuf)
8459 unlet s:netrwmarkfilelist_{ibuf}
8460 unlet s:netrwmarkfilemtch_{ibuf}
8461 endif
8462 let ibuf = ibuf + 1
8463 endwhile
8464 2match none
8465
Bram Moolenaar446cb832008-06-24 21:56:24 +00008466" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008467"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8468call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469" call Dret("s:NetrwUnMarkFile")
8470endfun
8471
8472" ---------------------------------------------------------------------
8473" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8474fun! s:NetrwMenu(domenu)
8475
8476 if !exists("g:NetrwMenuPriority")
8477 let g:NetrwMenuPriority= 80
8478 endif
8479
Bram Moolenaaradc21822011-04-01 18:03:16 +02008480 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8482
8483 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008484" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008485 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008486 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8490 if g:netrw_dirhistmax > 0
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8495 else
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8497 endif
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8512 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 +01008513 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 +02008514 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8543 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>'
8544 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>'
8545 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>'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8547 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>'
8548 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>'
8549 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 +01008550 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 +02008551 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008553 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008554 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8555 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008556
8557 elseif !a:domenu
8558 let s:netrwcnt = 0
8559 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008560 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561 exe curwin."wincmd w"
8562
8563 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008564" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008565 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008566" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008567 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568 endif
8569 endif
8570" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008571 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572 endif
8573
8574endfun
8575
8576" ---------------------------------------------------------------------
8577" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8578" Used by the O maps (as <SID>NetrwObtain())
8579fun! s:NetrwObtain(islocal)
8580" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8581
Bram Moolenaar97d62492012-11-15 21:28:22 +01008582 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008584 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008585 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008586 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8587 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008588 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008589 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008590 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591
8592" call Dret("NetrwObtain")
8593endfun
8594
8595" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8597" If there's only one window, then the window will first be split.
8598" Returns:
8599" choice = 0 : didn't have to choose
8600" choice = 1 : saved modified file in window first
8601" choice = 2 : didn't save modified file, opened window
8602" choice = 3 : cancel open
8603fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008604" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008605
Bram Moolenaar97d62492012-11-15 21:28:22 +01008606 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008608 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008609" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610
8611 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008612 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008613 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8615" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8616 let curword = s:NetrwGetWord()
8617 let choice = 0
8618 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8619" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008620 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008621" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008622 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008623" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008624" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008625" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626
Bram Moolenaar8d043172014-01-23 14:24:41 +01008627 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628 if lastwinnr == 1
8629 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008630" 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 +02008631 " g:netrw_preview=0: preview window shown in a horizontally split window
8632 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008634 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008635 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008636" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008637 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008639 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008640 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008642 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008644 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008646
8647 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008648" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008649 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008650" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008651 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008653 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008654" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008655 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008656" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008657" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008658" call Decho("COMBAK#12: mod=".&mod)
8659
8660 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8661 " whoops -- user trying to open file in the Lexplore window.
8662 " Use Lexplore's opening-file window instead.
8663" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8664" exe g:netrw_chgwin."wincmd w"
8665 wincmd p
8666 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8667 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008668
8669 " prevwinnr: the window number of the "prev" window
8670 " prevbufnr: the buffer number of the buffer in the "prev" window
8671 " bnrcnt : the qty of windows open on the "prev" buffer
8672 let prevwinnr = winnr()
8673 let prevbufnr = bufnr("%")
8674 let prevbufname = bufname("%")
8675 let prevmod = &mod
8676 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008677" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008678 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008679" 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 +01008680" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008681
8682 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008683 " and it doesn't appear in any other extant window, then ask the
8684 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008685 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008686" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008687 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008690" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008691
8692 if bnrcnt == 1 && &hidden == 0
8693 " only one copy of the modified buffer in a window, and
8694 " hidden not set, so overwriting will lose the modified file. Ask first...
8695 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008696" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008697 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008698" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008699
8700 if choice == 1
8701 " Yes -- write file & then browse
8702 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008703 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008705 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008706 exe origwin."wincmd w"
8707 let &ei = eikeep
8708 let @@ = ykeep
8709" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710 return choice
8711 endif
8712
8713 elseif choice == 2
8714 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008715" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008716 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717
8718 else
8719 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 exe origwin."wincmd w"
8722 let &ei= eikeep
8723 let @@ = ykeep
8724" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725 return choice
8726 endif
8727 endif
8728 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008729 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008731" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008732
8733 " restore b:netrw_curdir (window split/enew may have lost it)
8734 let b:netrw_curdir= curdir
8735 if a:islocal < 2
8736 if a:islocal
8737 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8738 else
8739 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8740 endif
8741 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008742 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008743" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744 return choice
8745endfun
8746
8747" ---------------------------------------------------------------------
8748" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8749" Always assumed to be local -> remote
8750" call s:NetrwUpload(filename, target)
8751" call s:NetrwUpload(filename, target, fromdirectory)
8752fun! s:NetrwUpload(fname,tgt,...)
8753" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8754
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008755 if a:tgt =~ '^\a\{3,}://'
8756 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008757 else
8758 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8759 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008761
8762 if a:0 > 0
8763 let fromdir= a:1
8764 else
8765 let fromdir= getcwd()
8766 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008767" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008768
8769 if type(a:fname) == 1
8770 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008771" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008773" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8774 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8775" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776 if a:tgt =~ '/$'
8777 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008779 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008781" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008782 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008784 endif
8785 q!
8786
8787 elseif type(a:fname) == 3
8788 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008790 let curdir= getcwd()
8791 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008792 if s:NetrwLcd(fromdir)
8793" call Dret("s:NetrwUpload : lcd failure")
8794 return
8795 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008796 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008797 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008798 if exists("g:netrw_port") && g:netrw_port != ""
8799 let useport= " ".g:netrw_scpport." ".g:netrw_port
8800 else
8801 let useport= ""
8802 endif
8803 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8804 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805 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 +02008806 if s:NetrwLcd(curdir)
8807" call Dret("s:NetrwUpload : lcd failure")
8808 return
8809 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810
8811 elseif a:tgt =~ '^ftp:'
8812 call s:NetrwMethod(a:tgt)
8813
8814 if b:netrw_method == 2
8815 " handle uploading a list of files via ftp+.netrc
8816 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008817 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008818" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008819
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008820 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822
8823 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008824 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008825" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008826 endif
8827
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008828 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008829" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830
Bram Moolenaaradc21822011-04-01 18:03:16 +02008831 if tgtdir == ""
8832 let tgtdir= '/'
8833 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008834 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008835" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836
8837 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008838 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8839" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008840 endfor
8841
8842 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 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 +00008844 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008845" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8846 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008847 endif
8848 " 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 +01008849 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008850 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8852 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8853 else
8854 bw!|q
8855 endif
8856
8857 elseif b:netrw_method == 3
8858 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8859 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008860 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008862 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863
8864 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008866" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008867 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008868 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008869" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008870 endif
8871
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008872 if exists("g:netrw_uid") && g:netrw_uid != ""
8873 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008874 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008876 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008877 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008878 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008879" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008880 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008881 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008882" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008883 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008884 endif
8885
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008888
8889 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008890 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008891" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008892 endif
8893
8894 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008896" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 endif
8898
8899 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endfor
8903
8904 " perform ftp:
8905 " -i : turns off interactive prompting from ftp
8906 " -n unix : DON'T use <.netrc>, even though it exists
8907 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008908 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008909 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910 " 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 +01008911 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008912 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008913 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8914 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008915 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008916 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8917 let &debug = debugkeep
8918 let mod = 1
8919 else
8920 bw!|q
8921 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008922 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008923" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008924 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008925 endif
8926 else
8927 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8928 endif
8929 endif
8930
8931" call Dret("s:NetrwUpload")
8932endfun
8933
8934" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008935" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936fun! s:NetrwPreview(path) range
8937" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008938" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8939" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008940 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941 NetrwKeepj call s:NetrwOptionsSave("s:")
8942 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8943 NetrwKeepj call s:NetrwOptionsSafe(1)
8944 else
8945 NetrwKeepj call s:NetrwOptionsSafe(0)
8946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008948" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008949 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8951 if g:netrw_preview
8952 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008953 let pvhkeep = &pvh
8954 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8955 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008956" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8957 else
8958 " horizontal split
8959 let pvhkeep = &pvh
8960 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8961 let &pvh = winheight(0) - winsz
8962" 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 +02008963 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008964 " g:netrw_preview g:netrw_alto
8965 " 1 : vert 1: top -- preview window is vertically split off and on the left
8966 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8967 " 0 : 1: top -- preview window is horizontally split off and on the top
8968 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8969 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008970 " 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 +02008971 " the BufEnter event set up in netrwPlugin.vim
8972" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8973 let eikeep = &ei
8974 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008975 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008976 let &ei= eikeep
8977" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008978 if exists("pvhkeep")
8979 let &pvh= pvhkeep
8980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008981 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008982 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983 endif
8984 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008985 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 +00008986 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008987 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008988 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008989" call Dret("NetrwPreview")
8990endfun
8991
8992" ---------------------------------------------------------------------
8993" s:NetrwRefresh: {{{2
8994fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008995" 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 +00008996 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008997 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008998" call Decho("setl ma noro",'~'.expand("<slnum>"))
8999" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009000 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009001 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9002 if !exists("w:netrw_treetop")
9003 if exists("b:netrw_curdir")
9004 let w:netrw_treetop= b:netrw_curdir
9005 else
9006 let w:netrw_treetop= getcwd()
9007 endif
9008 endif
9009 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9010 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009011
9012 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009013 let screenposn = winsaveview()
9014" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009015
9016" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9017" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9018 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009019 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009020 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009022 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009024
9025 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009026" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9027 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028
9029 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009030 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9031 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9032" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9033 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9034 else
9035" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9036 2match none
9037 endif
9038 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039
Bram Moolenaar97d62492012-11-15 21:28:22 +01009040" restore
9041 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009042" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009043endfun
9044
9045" ---------------------------------------------------------------------
9046" s:NetrwRefreshDir: refreshes a directory by name {{{2
9047" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009048" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009050" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051 if g:netrw_fastbrowse == 0
9052 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009053" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009055" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056
9057 if tgtwin > 0
9058 " tgtwin is being displayed, so refresh it
9059 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009062 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 exe curwin."wincmd w"
9064
9065 elseif bufnr(a:dirname) > 0
9066 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009067" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9068 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069 endif
9070
9071 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009073 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 endif
9075" call Dret("s:NetrwRefreshDir")
9076endfun
9077
9078" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009079" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9080" window number to do its editing in.
9081" Supports [count]C where the count, if present, is used to specify
9082" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009083fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009084" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009086" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 if a:1 == "" " :NetrwC win#
9088 let g:netrw_chgwin= winnr()
9089 else " :NetrwC
9090 let g:netrw_chgwin= a:1
9091 endif
9092 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009093 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009094 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009095 let g:netrw_chgwin= winnr()
9096 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009097 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009099endfun
9100
9101" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009102" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9103" What this function does is to compute a priority for the patterns
9104" in the g:netrw_sort_sequence. It applies a substitute to any
9105" "files" that satisfy each pattern, putting the priority / in
9106" front. An "*" pattern handles the default priority.
9107fun! s:NetrwSetSort()
9108" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009109 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009110 if w:netrw_liststyle == s:LONGLIST
9111 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9112 else
9113 let seqlist = g:netrw_sort_sequence
9114 endif
9115 " sanity check -- insure that * appears somewhere
9116 if seqlist == ""
9117 let seqlist= '*'
9118 elseif seqlist !~ '\*'
9119 let seqlist= seqlist.',*'
9120 endif
9121 let priority = 1
9122 while seqlist != ""
9123 if seqlist =~ ','
9124 let seq = substitute(seqlist,',.*$','','e')
9125 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9126 else
9127 let seq = seqlist
9128 let seqlist = ""
9129 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009130 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009131 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009132 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009133 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009135 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009137" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009138
9139 " sanity check
9140 if w:netrw_bannercnt > line("$")
9141 " apparently no files were left after a Hiding pattern was used
9142" call Dret("SetSort : no files left after hiding")
9143 return
9144 endif
9145 if seq == '*'
9146 let starpriority= spriority
9147 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009148 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009149 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150 " sometimes multiple sorting patterns will match the same file or directory.
9151 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009152 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9153 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154 endif
9155 let priority = priority + 1
9156 endwhile
9157 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009158 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9159 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160 endif
9161
9162 " Following line associated with priority -- items that satisfy a priority
9163 " pattern get prefixed by ###/ which permits easy sorting by priority.
9164 " Sometimes files can satisfy multiple priority patterns -- only the latest
9165 " priority pattern needs to be retained. So, at this point, these excess
9166 " priority prefixes need to be removed, but not directories that happen to
9167 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009168 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9169 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009170 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009171
9172" call Dret("SetSort")
9173endfun
9174
Bram Moolenaarff034192013-04-24 18:51:19 +02009175" ---------------------------------------------------------------------
9176" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9177" Implements [count]Tb (bookhist<b>)
9178" [count]Th (bookhist<h>)
9179" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009180fun! s:NetrwSetTgt(islocal,bookhist,choice)
9181" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009182
9183 if a:bookhist == 'b'
9184 " supports choosing a bookmark as a target using a qb-generated list
9185 let choice= a:choice - 1
9186 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009187 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009188 else
9189 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9190 endif
9191
9192 elseif a:bookhist == 'h'
9193 " supports choosing a history stack entry as a target using a qb-generated list
9194 let choice= (a:choice % g:netrw_dirhistmax) + 1
9195 if exists("g:netrw_dirhist_".choice)
9196 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009197 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009198 else
9199 echomsg "Sorry, history#".a:choice." not available!"
9200 endif
9201 endif
9202
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009203 " refresh the display
9204 if !exists("b:netrw_curdir")
9205 let b:netrw_curdir= getcwd()
9206 endif
9207 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9208
Bram Moolenaarff034192013-04-24 18:51:19 +02009209" call Dret("s:NetrwSetTgt")
9210endfun
9211
Bram Moolenaar446cb832008-06-24 21:56:24 +00009212" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009213" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214fun! s:NetrwSortStyle(islocal)
9215" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009216 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009217 let svpos= winsaveview()
9218" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009219
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009220 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 +01009221 NetrwKeepj norm! 0
9222 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009223" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9224 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009225
9226" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9227endfun
9228
9229" ---------------------------------------------------------------------
9230" s:NetrwSplit: mode {{{2
9231" =0 : net and o
9232" =1 : net and t
9233" =2 : net and v
9234" =3 : local and o
9235" =4 : local and t
9236" =5 : local and v
9237fun! s:NetrwSplit(mode)
9238" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9239
Bram Moolenaar97d62492012-11-15 21:28:22 +01009240 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241 call s:SaveWinVars()
9242
9243 if a:mode == 0
9244 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009245 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009246 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009247" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009248 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009250 NetrwKeepj call s:RestoreWinVars()
9251 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 unlet s:didsplit
9253
9254 elseif a:mode == 1
9255 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009256 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009257" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009258 tabnew
9259 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009260 NetrwKeepj call s:RestoreWinVars()
9261 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009262 unlet s:didsplit
9263
9264 elseif a:mode == 2
9265 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009266 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009267 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009268" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009269 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009271 NetrwKeepj call s:RestoreWinVars()
9272 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273 unlet s:didsplit
9274
9275 elseif a:mode == 3
9276 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009277 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009278 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009279" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009280 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009282 NetrwKeepj call s:RestoreWinVars()
9283 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 unlet s:didsplit
9285
9286 elseif a:mode == 4
9287 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009289 let eikeep = &ei
9290 let netrw_winnr = winnr()
9291 let netrw_line = line(".")
9292 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009293 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009294 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009295 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009296 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9297 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009298 let &ei = eikeep
9299 let netrw_curdir = s:NetrwTreeDir(0)
9300" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009301 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009302 let b:netrw_curdir = netrw_curdir
9303 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009304 NetrwKeepj call s:RestoreWinVars()
9305 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009306 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009307 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009308 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9309 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009310 let &ei= eikeep
9311 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009312 unlet s:didsplit
9313
9314 elseif a:mode == 5
9315 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009316 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009317 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009318" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009319 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009320 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009321 NetrwKeepj call s:RestoreWinVars()
9322 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323 unlet s:didsplit
9324
9325 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009327 endif
9328
Bram Moolenaar97d62492012-11-15 21:28:22 +01009329 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330" call Dret("s:NetrwSplit")
9331endfun
9332
9333" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009334" s:NetrwTgtMenu: {{{2
9335fun! s:NetrwTgtMenu()
9336 if !exists("s:netrw_menucnt")
9337 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009339" call Dfunc("s:NetrwTgtMenu()")
9340
9341 " the following test assures that gvim is running, has menus available, and has menus enabled.
9342 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9343 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009344" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009345 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9346 endif
9347 if !exists("s:netrw_initbookhist")
9348 call s:NetrwBookHistRead()
9349 endif
9350
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009351 " try to cull duplicate entries
9352 let tgtdict={}
9353
Bram Moolenaarff034192013-04-24 18:51:19 +02009354 " target bookmarked places
9355 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009357 let cnt= 1
9358 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359 if has_key(tgtdict,bmd)
9360 let cnt= cnt + 1
9361 continue
9362 endif
9363 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009364 let ebmd= escape(bmd,g:netrw_menu_escape)
9365 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009367 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 +02009368 let cnt= cnt + 1
9369 endfor
9370 endif
9371
9372 " target directory browsing history
9373 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009375 let histcnt = 1
9376 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009377 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009378 if exists("g:netrw_dirhist_{histcnt}")
9379 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009380 if has_key(tgtdict,histentry)
9381 let histcnt = histcnt + 1
9382 continue
9383 endif
9384 let tgtdict[histentry] = histcnt
9385 let ehistentry = escape(histentry,g:netrw_menu_escape)
9386" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009387 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 +02009388 endif
9389 let histcnt = histcnt + 1
9390 endwhile
9391 endif
9392 endif
9393" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009394endfun
9395
9396" ---------------------------------------------------------------------
9397" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9398" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009399fun! s:NetrwTreeDir(islocal)
9400" 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 +02009401" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009402" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9403" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9404" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009405" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009407 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009408 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009409" 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 +01009410 let treedir= s:treedir
9411 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009412 unlet s:prevwinopen
9413" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009414 return treedir
9415 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009416 if exists("s:prevwinopen")
9417 unlet s:prevwinopen
9418 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009419" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009420
Bram Moolenaar8d043172014-01-23 14:24:41 +01009421 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9422 let b:netrw_curdir= getcwd()
9423 endif
9424 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009426" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009427
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009428 let s:treecurpos= winsaveview()
9429" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009430" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009431
9432 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009433" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9434" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009436
9437 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009438 let curline= substitute(getline('.'),"\t -->.*$",'','')
9439 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009440" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009441 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9443 elseif curline =~ '@$'
9444" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009445 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009446" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009447 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 let treedir= ""
9450 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009451" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452
9453 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9455" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009456" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009457 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9461 sil! NetrwKeepj %d _
9462" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009463 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009464" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009465" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009466 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009467" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009469" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009470" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009471" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009472
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009473 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9474" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9475" let newdir = w:netrw_treetop.'/'.potentialdir
9476" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9477" let treedir = s:NetrwTreePath(newdir)
9478" let w:netrw_treetop = newdir
9479" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9480" else
9481" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009482 if a:islocal && curline =~ '@$'
9483 if isdirectory(s:NetrwFile(potentialdir))
9484 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9485 let w:netrw_treetop = treedir
9486 endif
9487 else
9488 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9489 let treedir = s:NetrwTreePath(w:netrw_treetop)
9490 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009491 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009492" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009493
9494 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009495 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009496" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009497" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009498
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009499" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 return treedir
9501endfun
9502
9503" ---------------------------------------------------------------------
9504" s:NetrwTreeDisplay: recursive tree display {{{2
9505fun! s:NetrwTreeDisplay(dir,depth)
9506" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9507
9508 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009509 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009510
9511 " install ../ and shortdir
9512 if a:depth == ""
9513 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009514" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 if a:dir == w:netrw_treetop
9518 let shortdir= a:dir
9519 else
9520 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9521 endif
9522 call setline(line("$")+1,a:depth.shortdir)
9523 else
9524 let shortdir= substitute(a:dir,'^.*/','','e')
9525 call setline(line("$")+1,a:depth.shortdir.'/')
9526 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009527" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009528 " append a / to dir if its missing one
9529 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530
9531 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009532 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009533" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009534
Bram Moolenaar85850f32019-07-19 22:05:51 +02009535 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9536 if g:netrw_hide == 1
9537 " hide given patterns
9538 let listhide= split(g:netrw_list_hide,',')
9539" call Decho("listhide=".string(listhide))
9540 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009541 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009542 endfor
9543
9544 elseif g:netrw_hide == 2
9545 " show given patterns (only)
9546 let listhide= split(g:netrw_list_hide,',')
9547" call Decho("listhide=".string(listhide))
9548 let entries=[]
9549 for entry in w:netrw_treedict[dir]
9550 for pat in listhide
9551 if entry =~ pat
9552 call add(entries,entry)
9553 break
9554 endif
9555 endfor
9556 endfor
9557 let w:netrw_treedict[dir]= entries
9558 endif
9559 if depth != ""
9560 " always remove "." and ".." entries when there's depth
9561 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9562 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9563 endif
9564
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009565" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009566 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009567 if dir =~ '/$'
9568 let direntry= substitute(dir.entry,'[@/]$','','e')
9569 else
9570 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9571 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009572" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009573 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009574" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009575 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9578 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9579 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9580" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009581 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009583" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009584 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585 endif
9586 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009587" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009588
Bram Moolenaar446cb832008-06-24 21:56:24 +00009589" call Dret("NetrwTreeDisplay")
9590endfun
9591
9592" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009593" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9594fun! s:NetrwRefreshTreeDict(dir)
9595" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009596 if !exists("w:netrw_treedict")
9597" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9598 return
9599 endif
9600
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009601 for entry in w:netrw_treedict[a:dir]
9602 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9603" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9604
9605 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9606" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9607 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009608 let liststar = s:NetrwGlob(direntry,'*',1)
9609 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009610 let w:netrw_treedict[direntry] = liststar + listdotstar
9611" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9612
9613 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9614" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9615 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009616 let liststar = s:NetrwGlob(direntry.'/','*',1)
9617 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009618 let w:netrw_treedict[direntry]= liststar + listdotstar
9619" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9620
9621 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9622" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9623 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009624 let liststar = s:NetrwGlob(direntry.'/','*',1)
9625 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009626" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9627
9628 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009629" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009630 endif
9631 endfor
9632" call Dret("s:NetrwRefreshTreeDict")
9633endfun
9634
9635" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009636" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009637" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009639 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009640" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009641" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9642" 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>"))
9643" 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 +00009644
9645 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009647" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009649 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 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 +02009652" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009654 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009657 if exists("w:netrw_treetop")
9658 let s:netrw_treetop= w:netrw_treetop
9659 else
9660 let w:netrw_treetop= getcwd()
9661 let s:netrw_treetop= w:netrw_treetop
9662 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665 " insure that we have a treedict, albeit empty
9666" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 let w:netrw_treedict= {}
9668 endif
9669
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009670 " update the dictionary for the current directory
9671" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009672" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009673 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009675" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009676 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009677
9678 " if past banner, record word
9679 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9680 let fname= expand("<cword>")
9681 else
9682 let fname= ""
9683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9685" 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 +00009686
9687 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009688" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009689 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009690" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009691
9692 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9693 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009694" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009695 1d
9696 endwhile
9697
Bram Moolenaar13600302014-05-22 18:26:40 +02009698 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009700" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009701 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 endif
9703endfun
9704
9705" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009706" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009707" Normally, treetop is w:netrw_treetop, but a
9708" user of the function ( netrw#SetTreetop() )
9709" wipes that out prior to calling this function
9710fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009711" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9712 if line(".") < w:netrw_bannercnt + 2
9713 let treedir= a:treetop
9714 if treedir !~ '/$'
9715 let treedir= treedir.'/'
9716 endif
9717" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9718 return treedir
9719 endif
9720
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009721 let svpos = winsaveview()
9722" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009723 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009724" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009725 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009726" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9727 let curline= getline('.')
9728" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9729 if curline =~ '/$'
9730" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9731 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9732" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9733 elseif curline =~ '@\s\+-->'
9734" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9735 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9736 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9737" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009738 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009740 let treedir= ""
9741 endif
9742 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009743" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9744" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9746 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9747 let treedir= dirname.treedir
9748 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009749" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009751" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 if a:treetop =~ '/$'
9753 let treedir= a:treetop.treedir
9754 else
9755 let treedir= a:treetop.'/'.treedir
9756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009757" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009758 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009759" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009760" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9761 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009762" call Dret("s:NetrwTreePath <".treedir.">")
9763 return treedir
9764endfun
9765
9766" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009767" s:NetrwWideListing: {{{2
9768fun! s:NetrwWideListing()
9769
9770 if w:netrw_liststyle == s:WIDELIST
9771" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9772 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009773 " cpf: characters per filename
9774 " fpl: filenames per line
9775 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009776 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009777 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009778" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 let b:netrw_cpf= 0
9780 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009781 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009782 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9783 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009784 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009785 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009786" call Dret("NetrwWideListing")
9787 return
9788 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009789 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009790 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009791" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009792
9793 " determine qty files per line (fpl)
9794 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9795 if w:netrw_fpl <= 0
9796 let w:netrw_fpl= 1
9797 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009798" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009799
9800 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009801 " fpc: files per column of wide listing
9802 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009803 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9805 let newcolstart = w:netrw_bannercnt + fpc
9806 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009807" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009808 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009809" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009810 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009811 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009812 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 while line("$") >= newcolstart
9814 if newcolend > line("$") | let newcolend= line("$") | endif
9815 let newcolqty= newcolend - newcolstart
9816 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009817 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009819 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009821 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009823 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009824 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009826 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009827" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009828 if @* != keepregstar | sil! let @* = keepregstar | endif
9829 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009830 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009831 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9832 NetrwKeepj call histdel("/",-1)
9833 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9834 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009835" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009836 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009837 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009838" 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 +00009839" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009840 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009841 else
9842 if hasmapto("w","n")
9843 sil! nunmap <buffer> w
9844 endif
9845 if hasmapto("b","n")
9846 sil! nunmap <buffer> b
9847 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 endif
9849
9850endfun
9851
9852" ---------------------------------------------------------------------
9853" s:PerformListing: {{{2
9854fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009855" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9856" 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 +02009857" 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>"))
9858 sil! NetrwKeepj %d _
9859" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860
Bram Moolenaar15146672011-10-20 22:22:38 +02009861 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009862" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009863 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009864
Bram Moolenaar85850f32019-07-19 22:05:51 +02009865 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009866 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868
9869" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009870" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871" endif " Decho
9872
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9875 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009876" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9877 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878 endif
9879
9880 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009881 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882
9883 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009884 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009885" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009886 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887 if exists("g:netrw_pchk")
9888 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9889 " failure detections.
9890 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009891 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9893 endif
9894 if exists("g:netrw_pchk")
9895 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9896 else
9897 let curdir= b:netrw_curdir
9898 endif
9899 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9900 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9901 else
9902 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009903 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009904 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009905 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009908 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009909 let w:netrw_bannercnt= 1
9910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9912" 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 +00009913
Bram Moolenaar85850f32019-07-19 22:05:51 +02009914 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009915 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009916 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009917 let sortby= sortby." reversed"
9918 endif
9919
9920 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009921 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009923 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009925 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009926 NetrwKeepj put ='\" Sorted by '.sortby
9927 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009928 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9929 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009931 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009932 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009933 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9934 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009935 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009936" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" 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 +00009938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939
Bram Moolenaar85850f32019-07-19 22:05:51 +02009940 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 if g:netrw_banner
9942 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009944 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009945 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 endif
9950 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009953 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956
9957 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009958 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009959" 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 +01009960 if g:netrw_list_hide != "" && g:netrw_hide
9961 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009965 endif
9966 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009969
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009970" 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 +01009971 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009972" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009973 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009974" 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 +01009975 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009977" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" 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 +00009979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009980
9981 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009982 if g:netrw_banner
9983 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" 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 +01009986" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" 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 +01009988 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009991" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009992 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009993 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009996 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009997" 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 +01009998" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9999 return
10000 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002
10003 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010004 if !exists("w:netrw_bannercnt")
10005 let w:netrw_bannercnt= 0
10006 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10008" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10009" 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 +010010010
Bram Moolenaar5c736222010-01-06 20:54:52 +010010011 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010012" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" 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 +000010014 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010015 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010017 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010019
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010020 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010021 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010022" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010023 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024
Bram Moolenaar5c736222010-01-06 20:54:52 +010010025 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010027 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010028 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010029 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030 else
10031 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010032 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010033 endif
10034 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010035
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010038 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10039 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010041 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010042 " exten: sort by extension
10043 " The histdel(...,-1) calls remove the last search from the search history
10044" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10046 NetrwKeepj call histdel("/",-1)
10047 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10048 NetrwKeepj call histdel("/",-1)
10049 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10050 NetrwKeepj call histdel("/",-1)
10051 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10052" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010053 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010054 " normal direction sorting
10055 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10056 else
10057 " reverse direction sorting
10058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10059 endif
10060 endif
10061 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10062 NetrwKeepj call histdel("/",-1)
10063
Bram Moolenaar446cb832008-06-24 21:56:24 +000010064 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010065 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010066" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010067 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010068" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010069 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010070 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010072 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010073 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010074" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010075 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10076 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010077 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010078 endif
10079
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010080 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010081" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010082 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010084 call histdel("/",-1)
10085 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010086 endif
10087 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088" 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 +000010089
10090 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010091" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10092" 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 +010010093 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" 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 +010010095 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" 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 +000010097
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010098 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010099 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010101 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010102 endif
10103
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010105 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10107 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010108 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10110 else
10111" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10112" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10113" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10114" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010115 endif
10116
10117 " record previous current directory
10118 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010119" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010120
10121 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10123" 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 +010010124 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" 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 +020010126 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" 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 +000010128
10129 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010131 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" 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 +010010133 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010135 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10136 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010137" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010138" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010139
Bram Moolenaar8d043172014-01-23 14:24:41 +010010140 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10142" 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 +010010143" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10144 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010145 unlet s:treecurpos
10146 endif
10147
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" 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>"))
10149" 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 +000010150" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10151endfun
10152
10153" ---------------------------------------------------------------------
10154" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010155fun! s:SetupNetrwStatusLine(statline)
10156" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10157
10158 if !exists("s:netrw_setup_statline")
10159 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010161
10162 if !exists("s:netrw_users_stl")
10163 let s:netrw_users_stl= &stl
10164 endif
10165 if !exists("s:netrw_users_ls")
10166 let s:netrw_users_ls= &laststatus
10167 endif
10168
10169 " set up User9 highlighting as needed
10170 let keepa= @a
10171 redir @a
10172 try
10173 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010174 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010175 if &bg == "dark"
10176 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10177 else
10178 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10179 endif
10180 endtry
10181 redir END
10182 let @a= keepa
10183 endif
10184
10185 " set up status line (may use User9 highlighting)
10186 " insure that windows have a statusline
10187 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010188 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010189 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010190" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010191 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010192
10193" call Dret("SetupNetrwStatusLine : stl=".&stl)
10194endfun
10195
Bram Moolenaar85850f32019-07-19 22:05:51 +020010196" =========================================
10197" Remote Directory Browsing Support: {{{1
10198" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010199
10200" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010201" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10202" This function assumes that a long listing will be received. Size, time,
10203" and reverse sorts will be requested of the server but not otherwise
10204" enforced here.
10205fun! s:NetrwRemoteFtpCmd(path,listcmd)
10206" 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 +010010207" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010208 " sanity check: {{{3
10209 if !exists("w:netrw_method")
10210 if exists("b:netrw_method")
10211 let w:netrw_method= b:netrw_method
10212 else
10213 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10214" call Dret("NetrwRemoteFtpCmd")
10215 return
10216 endif
10217 endif
10218
10219 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10220 let ffkeep= &ff
10221 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010222" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010223
10224 " clear off any older non-banner lines " {{{3
10225 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010226" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10227 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010228
10229 ".........................................
10230 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10231 " ftp + <.netrc>: Method #2
10232 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010233 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010234 endif
10235 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010236 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010237" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010238 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010239 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010240" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010241 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010242" 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>"))
10243 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 +010010244 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010245" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10246 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 +010010247 endif
10248
10249 ".........................................
10250 elseif w:netrw_method == 3 " {{{3
10251 " ftp + machine,id,passwd,filename: Method #3
10252 setl ff=unix
10253 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010254 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010255 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 endif
10258
10259 " handle userid and password
10260 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010261" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010262 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10263 call NetUserPass("ftp:".host)
10264 endif
10265 if exists("g:netrw_uid") && g:netrw_uid != ""
10266 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010267 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010268 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010269 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010270 endif
10271 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010272 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 endif
10274 endif
10275
10276 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010277 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010278 endif
10279 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010280 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010281" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010283 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010284
10285 " perform ftp:
10286 " -i : turns off interactive prompting from ftp
10287 " -n unix : DON'T use <.netrc>, even though it exists
10288 " -n win32: quit being obnoxious about password
10289 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010290" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010291 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010292" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010293" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10294" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 endif
10296
10297 ".........................................
10298 elseif w:netrw_method == 9 " {{{3
10299 " sftp username@machine: Method #9
10300 " s:netrw_sftp_cmd
10301 setl ff=unix
10302
10303 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010304 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010305" call Dret("NetrwRemoteFtpCmd")
10306 return
10307
10308 ".........................................
10309 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010310 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010311 endif
10312
10313 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010314 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010315 sil! NetrwKeepj %s/\r$//e
10316 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010317 endif
10318 if a:listcmd == "dir"
10319 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010320 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10321 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10322 NetrwKeepj call histdel("/",-1)
10323 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010324 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 +010010325 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10326 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010327 endif
10328 endif
10329
10330 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10331 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 exe 'NetrwKeepj '.w:netrw_bannercnt
10333 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010334 endif
10335 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010336 exe 'NetrwKeepj '.w:netrw_bannercnt
10337 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010338 endif
10339
10340 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010341 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010342" call Dret("NetrwRemoteFtpCmd")
10343endfun
10344
10345" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010346" s:NetrwRemoteListing: {{{2
10347fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010348" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010349
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10351 let w:netrw_bannercnt= s:bannercnt
10352 endif
10353 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010354 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 endif
10356
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010358
Bram Moolenaar446cb832008-06-24 21:56:24 +000010359 " sanity check:
10360 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010361" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010363" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364 if !exists("g:netrw_quiet")
10365 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10366 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010367 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010368" call Dret("s:NetrwRemoteListing -1")
10369 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371
Bram Moolenaar8d043172014-01-23 14:24:41 +010010372 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010373" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010375 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010376 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 +000010377 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010378 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 +000010379 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010380 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010381
Bram Moolenaar85850f32019-07-19 22:05:51 +020010382 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010383" call Dret("s:NetrwRemoteListing -1")
10384 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010386" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010387
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 let w:netrw_method= b:netrw_method
10391 endif
10392
Bram Moolenaar13600302014-05-22 18:26:40 +020010393 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010394 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010396 let s:method = "ftp"
10397 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010398 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010400 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010401 let listcmd= g:netrw_ftp_sizelist_cmd
10402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010403" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010404 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010405" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406
Bram Moolenaara6878372014-03-22 21:02:50 +010010407 " report on missing file or directory messages
10408 if search('[Nn]o such file or directory\|Failed to change directory')
10409 let mesg= getline(".")
10410 if exists("w:netrw_bannercnt")
10411 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010412 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010413 setl noma
10414 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010415 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010416 call netrw#ErrorMsg(s:WARNING,mesg,96)
10417" call Dret("s:NetrwRemoteListing : -1")
10418 return -1
10419 endif
10420
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010421 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 +000010422 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010423" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010424 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010425
10426 " cleanup
10427 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010428 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10429 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010430 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010431 sil! NetrwKeepj %s/\r$//e
10432 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010433
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010434 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010437 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010438" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010441 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 exe "sil! NetrwKeepj ".line1
10444 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010449 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10450 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010452" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10454 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10455 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10456 NetrwKeepj call histdel("/",-1)
10457 NetrwKeepj call histdel("/",-1)
10458 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 endif
10460 endif
10461
Bram Moolenaar13600302014-05-22 18:26:40 +020010462 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10469 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010471 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10472 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10473 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10474 NetrwKeepj call histdel("/",-1)
10475 NetrwKeepj call histdel("/",-1)
10476 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10479 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010480 endif
10481 else
10482 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010483" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010484 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10487 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10488" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 endif
10490 endif
10491
10492 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010493 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010494" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010495 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10496 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 endif
10498 endif
10499
10500 if w:netrw_liststyle == s:LONGLIST
10501 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503
10504 if s:method == "ftp"
10505 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010506 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010507 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010508 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010510 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010512 sil! NetrwKeepj 1
10513 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 let line2= line(".")
10515 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010517 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 endif
10519 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 exe "sil! NetrwKeepj ".line1
10521 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010522 endif
10523
10524 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010525" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010526 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 +000010527 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010528" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010530 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010531 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10532 NetrwKeepj call histdel("/",-1)
10533 NetrwKeepj call histdel("/",-1)
10534 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 endif
10536 endif
10537
10538" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010541
10542" call Dret("s:NetrwRemoteListing 0")
10543 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010544endfun
10545
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546" ---------------------------------------------------------------------
10547" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10548fun! s:NetrwRemoteRm(usrhost,path) range
10549" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010550" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010551 let svpos= winsaveview()
10552" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553
10554 let all= 0
10555 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10556 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010557" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558 for fname in s:netrwmarkfilelist_{bufnr("%")}
10559 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010560 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010562 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 let all= 1
10564 endif
10565 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010566 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567
10568 else
10569 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010570" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571
10572 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573 let keepsol = &l:sol
10574 setl nosol
10575 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576
10577 " remove multiple files and directories
10578 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010579 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010581 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010583 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 let all= 1
10585 endif
10586 let ctr= ctr + 1
10587 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010588 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 endif
10590
10591 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010593 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010594" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10595 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596
10597" call Dret("s:NetrwRemoteRm")
10598endfun
10599
10600" ---------------------------------------------------------------------
10601" s:NetrwRemoteRmFile: {{{2
10602fun! s:NetrwRemoteRmFile(path,rmfile,all)
10603" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10604
10605 let all= a:all
10606 let ok = ""
10607
10608 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10609 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010610" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010611 if !all
10612 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010613" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614 call inputsave()
10615 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10616 call inputrestore()
10617 echohl NONE
10618 if ok == ""
10619 let ok="no"
10620 endif
10621 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010622 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 let all= 1
10624 endif
10625 endif
10626
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010627 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010628" 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 +000010629 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632 if path =~ '^\a\{3,}://'
10633 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010635 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10637 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010638" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010641 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010642 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 let ok="q"
10644 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010645 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10647" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10648" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010654" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656 if v:shell_error != 0
10657 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010658 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 +010010659 else
10660 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10661 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010662 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 endif
10667 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010668 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010669" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010670 endif
10671
10672 else
10673 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 if !all
10676 call inputsave()
10677 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10678 call inputrestore()
10679 if ok == ""
10680 let ok="no"
10681 endif
10682 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010683 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 let all= 1
10685 endif
10686 endif
10687
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010688 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010690 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691 else
10692 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10694" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010695 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010697
10698 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10700 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10701" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010702 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010703" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704
10705 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010706 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010707 endif
10708 endif
10709 endif
10710
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010711 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713 endif
10714 endif
10715
10716" call Dret("s:NetrwRemoteRmFile ".ok)
10717 return ok
10718endfun
10719
10720" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010721" s:NetrwRemoteRename: rename a remote file or directory {{{2
10722fun! s:NetrwRemoteRename(usrhost,path) range
10723" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10724
10725 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010726 let svpos = winsaveview()
10727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010728 let ctr = a:firstline
10729 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10730
10731 " rename files given by the markfilelist
10732 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10733 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010734" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735 if exists("subfrom")
10736 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010737" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010738 else
10739 call inputsave()
10740 let newname= input("Moving ".oldname." to : ",oldname)
10741 call inputrestore()
10742 if newname =~ '^s/'
10743 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10744 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10745 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 endif
10748 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010751 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010752 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010753 let oldname= s:ShellEscape(a:path.oldname)
10754 let newname= s:ShellEscape(a:path.newname)
10755" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010756 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010757 endif
10758
10759 endfor
10760 call s:NetrwUnMarkFile(1)
10761
10762 else
10763
10764 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765 let keepsol= &l:sol
10766 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010767 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010768 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769
10770 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772
10773 call inputsave()
10774 let newname= input("Moving ".oldname." to : ",oldname)
10775 call inputrestore()
10776
10777 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10778 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10779 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010780 let oldname= s:ShellEscape(a:path.oldname)
10781 let newname= s:ShellEscape(a:path.newname)
10782" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010783 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784 endif
10785
10786 let ctr= ctr + 1
10787 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010788 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010789 endif
10790
10791 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010792 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010793" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10794 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795
10796" call Dret("NetrwRemoteRename")
10797endfun
10798
Bram Moolenaar85850f32019-07-19 22:05:51 +020010799" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010800" Local Directory Browsing Support: {{{1
10801" ==========================================
10802
10803" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010804" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010805" Should accept: file://localhost/etc/fstab
10806" file:///etc/fstab
10807" file:///c:/WINDOWS/clock.avi
10808" file:///c|/WINDOWS/clock.avi
10809" file://localhost/c:/WINDOWS/clock.avi
10810" file://localhost/c|/WINDOWS/clock.avi
10811" file://c:/foo.txt
10812" file:///c:/foo.txt
10813" 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 +020010814fun! netrw#FileUrlEdit(fname)
10815" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010816 let fname = a:fname
10817 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010818" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010819 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010822 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010823 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010824" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010826" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010827 endif
10828 endif
10829 let fname2396 = netrw#RFC2396(fname)
10830 let fname2396e= fnameescape(fname2396)
10831 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010832 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010834 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10837 endif
10838 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010839
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10841" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010843 exe 'NetrwKeepj keepalt edit '.plainfname
10844 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10845
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" 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 +020010847" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 exe "sil doau BufReadPost ".fname2396e
10849endfun
10850
10851" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010852" netrw#LocalBrowseCheck: {{{2
10853fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010854 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010855 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10856 "
10857 " unfortunate interaction -- split window debugging can't be used here, must use
10858 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10859 " another call to LocalBrowseCheck() when attempts to write
10860 " to the DBG buffer are made.
10861 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010862 " The &ft == "netrw" test was installed because the BufEnter event
10863 " would hit when re-entering netrw windows, creating unexpected
10864 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010865" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010866" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010867" 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 +010010868 " getting E930: Cannot use :redir inside execute
10869"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010870" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10871" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010872
Bram Moolenaar97d62492012-11-15 21:28:22 +010010873 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874 if isdirectory(s:NetrwFile(a:dirname))
10875" 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 +010010876
Bram Moolenaar97d62492012-11-15 21:28:22 +010010877 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010878" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10879" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010880 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010881
Bram Moolenaar446cb832008-06-24 21:56:24 +000010882 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010884 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010885
Bram Moolenaar5c736222010-01-06 20:54:52 +010010886 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010888 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010889 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010890 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010891" 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 +010010892" call Dret("netrw#LocalBrowseCheck")
10893 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010894 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010895
Bram Moolenaar85850f32019-07-19 22:05:51 +020010896 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010897 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10898 " AND IF the listing style is not a tree listing
10899 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010901 let ibuf = 1
10902 let buflast = bufnr("$")
10903 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10905 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010906 endif
10907 let ibuf= ibuf + 1
10908 endwhile
10909 endif
10910 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010911" 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>"))
10912" 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 +000010913 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010914" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010915endfun
10916
10917" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010918" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010919" performed any shell command. The idea is to cause all local-browsing
10920" buffers to be refreshed after a user has executed some shell command,
10921" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010922fun! s:LocalBrowseRefresh()
10923" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010924" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10925" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010926
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927 " determine which buffers currently reside in a tab
10928 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010929" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010930 return
10931 endif
10932 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010933" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010934 return
10935 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010936 if !empty(getcmdwintype())
10937 " cannot move away from cmdline window, see :h E11
10938 return
10939 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010940 if exists("s:netrw_events") && s:netrw_events == 1
10941 " s:LocalFastBrowser gets called (indirectly) from a
10942 let s:netrw_events= 2
10943" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10944 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010945 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010946 let itab = 1
10947 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010948 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010949 while itab <= tabpagenr("$")
10950 let buftablist = buftablist + tabpagebuflist()
10951 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010952 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010954" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10955" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10957 " | refresh any netrw window
10958 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010959 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010960 let ibl = 0
10961 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010962" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010963 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10964 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010965 " (ibuf not shown in a current window AND
10966 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010967" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10968 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 continue
10972 elseif index(tabpagebuflist(),ibuf) != -1
10973 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010976 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010977 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10978 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10979 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10980 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010981" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010982 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10983 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10984 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010985 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010986 endif
10987 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010988" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010989 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010990" call Decho("restore window: win_gotoid(".curwinid.")")
10991 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010992 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010993
Bram Moolenaara6878372014-03-22 21:02:50 +010010994" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995endfun
10996
10997" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010998" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10999"
11000" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011001" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011002" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11003" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011005"
11006" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11007" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011008" (re-using a buffer may not be as accurate)
11009"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011010" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011011" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11012" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11013" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11014" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011015fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011016" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11017" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11018" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11019" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011020
11021 " initialize browselist, a list of buffer numbers that the local browser has used
11022 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024 let s:netrw_browselist= []
11025 endif
11026
11027 " append current buffer to fastbrowse list
11028 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011029" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011030 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032 endif
11033
11034 " enable autocmd events to handle refreshing/removing local browser buffers
11035 " If local browse buffer is currently showing: refresh it
11036 " If local browse buffer is currently hidden : wipe it
11037 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11038 " =1 : medium speed, re-use directory listing for remote only
11039 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011040 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11041 let s:netrw_events= 1
11042 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011043 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011044 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011046 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011047 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011049 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011050 endif
11051 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052
11053 " user must have changed fastbrowse to its fast setting, so remove
11054 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011055 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011056" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 unlet s:netrw_events
11058 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 au!
11060 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011062 endif
11063
Bram Moolenaar85850f32019-07-19 22:05:51 +020011064" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011065endfun
11066
11067" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011068" s:LocalListing: does the job of "ls" for local directories {{{2
11069fun! s:LocalListing()
11070" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011071" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11072" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11073" 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 +010011074
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011075" 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
11076" 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
11077" 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 +010011078
11079 " get the list of files contained in the current directory
11080 let dirname = b:netrw_curdir
11081 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011082 let filelist = s:NetrwGlob(dirname,"*",0)
11083 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011084" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011085
Nir Lichtman1e34b952024-05-08 19:19:34 +020011086 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011088 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11089 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011091 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011092" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011093 endif
11094
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011095" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011097" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011098
11099 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11100 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11101 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11103" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011104 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" 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 +010011106
11107 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho(" ",'~'.expand("<slnum>"))
11109" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110
11111 if getftype(filename) == "link"
11112 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011114 let pfile= filename."@"
11115
11116 elseif getftype(filename) == "socket"
11117 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119 let pfile= filename."="
11120
11121 elseif getftype(filename) == "fifo"
11122 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011123" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011124 let pfile= filename."|"
11125
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011126 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011127 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 let pfile= filename."/"
11130
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011132 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011133 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11134 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."*"
11137 else
11138 " normal file
11139 let pfile= filename
11140 endif
11141 elseif executable(filename)
11142 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011144 let pfile= filename."*"
11145 else
11146 " normal file
11147 let pfile= filename
11148 endif
11149
11150 else
11151 " normal file
11152 let pfile= filename
11153 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011155
11156 if pfile =~ '//$'
11157 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011159 endif
11160 let pfile= strpart(pfile,dirnamelen)
11161 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011162" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11163" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011164
11165 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011166 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11167 let sz = getfsize(filename)
11168 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11169 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011170
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011171 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011172 let sz= s:NetrwHumanReadable(sz)
11173 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011174 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011175 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011176" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011177 endif
11178
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011179 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011180 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011181 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011182" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011183" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011184 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011185 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011186" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011187 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011188 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011189
11190 elseif g:netrw_sort_by =~ "^s"
11191 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011192" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011193" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011194 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011195 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011196" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011197 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011198 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011199
11200 else
11201 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011202" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011203" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011204 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011205 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011206" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011207 endfor
11208
11209 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011210 sil! NetrwKeepj g/^$/d
11211 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011212 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011213" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11215
11216" call Dret("s:LocalListing")
11217endfun
11218
11219" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011220" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11221fun! s:NetrwLocalExecute(cmd)
11222" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11223 let ykeep= @@
11224 " sanity check
11225 if !executable(a:cmd)
11226 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11227 let @@= ykeep
11228" call Dret("s:NetrwLocalExecute")
11229 return
11230 endif
11231
11232 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011233" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011234 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011235" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011236
11237 " strip any ansi escape sequences off
11238 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11239
11240 " show user the result(s)
11241 echomsg result
11242 let @@= ykeep
11243
11244" call Dret("s:NetrwLocalExecute")
11245endfun
11246
11247" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011248" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011249fun! s:NetrwLocalRename(path) range
11250" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11251
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011252 if !exists("w:netrw_bannercnt")
11253 let w:netrw_bannercnt= b:netrw_bannercnt
11254 endif
11255
Bram Moolenaar97d62492012-11-15 21:28:22 +010011256 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011257 let ykeep = @@
11258 let ctr = a:firstline
11259 let svpos = winsaveview()
11260 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011261" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011262
11263 " rename files given by the markfilelist
11264 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11265 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011266" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011267 if exists("subfrom")
11268 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011269" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011270 else
11271 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011272 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011273 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011274 if newname =~ ''
11275 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11276 let newname = substitute(newname,'^.*','','')
11277 elseif newname =~ ''
11278 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11279 let newname = substitute(newname,'[^/]*','','')
11280 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011281 if newname =~ '^s/'
11282 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11283 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011284" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285 let newname = substitute(oldname,subfrom,subto,'')
11286 endif
11287 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011288 if !all && filereadable(newname)
11289 call inputsave()
11290 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11291 call inputrestore()
11292 if response == "all"
11293 let all= 1
11294 elseif response != "y" && response != "yes"
11295 " refresh the directory
11296" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11297 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11298" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11299 NetrwKeepj call winrestview(svpos)
11300 let @@= ykeep
11301" call Dret("NetrwLocalRename")
11302 return
11303 endif
11304 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011305 call rename(oldname,newname)
11306 endfor
11307 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011308
Bram Moolenaar97d62492012-11-15 21:28:22 +010011309 else
11310
11311 " attempt to rename files/directories
11312 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011313 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011314
11315 " sanity checks
11316 if line(".") < w:netrw_bannercnt
11317 let ctr= ctr + 1
11318 continue
11319 endif
11320 let curword= s:NetrwGetWord()
11321 if curword == "./" || curword == "../"
11322 let ctr= ctr + 1
11323 continue
11324 endif
11325
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011326 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011327 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011328" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011329
11330 call inputsave()
11331 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11332 call inputrestore()
11333
11334 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011335" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011336
11337 let ctr= ctr + 1
11338 endwhile
11339 endif
11340
11341 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011342" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011343 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011344" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11345 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011346 let @@= ykeep
11347
11348" call Dret("NetrwLocalRename")
11349endfun
11350
11351" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011352" s:NetrwLocalRm: {{{2
11353fun! s:NetrwLocalRm(path) range
11354" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011355" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011356
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011357 if !exists("w:netrw_bannercnt")
11358 let w:netrw_bannercnt= b:netrw_bannercnt
11359 endif
11360
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011362 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011363 let ret = 0
11364 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011365 let svpos = winsaveview()
11366" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367
11368 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11369 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011370" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011371 for fname in s:netrwmarkfilelist_{bufnr("%")}
11372 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011373 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011374 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011375 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376 let all= 1
11377 endif
11378 endfor
11379 call s:NetrwUnMarkFile(1)
11380
11381 else
11382 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011383" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011384
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011385 let keepsol= &l:sol
11386 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011387 let ctr = a:firstline
11388 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011389 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390
11391 " sanity checks
11392 if line(".") < w:netrw_bannercnt
11393 let ctr= ctr + 1
11394 continue
11395 endif
11396 let curword= s:NetrwGetWord()
11397 if curword == "./" || curword == "../"
11398 let ctr= ctr + 1
11399 continue
11400 endif
11401 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011402 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011403 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011404 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405 let all= 1
11406 endif
11407 let ctr= ctr + 1
11408 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011409 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011410 endif
11411
11412 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011413" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011415 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011416" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11417 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011418 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011419 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011420
11421" call Dret("s:NetrwLocalRm")
11422endfun
11423
11424" ---------------------------------------------------------------------
11425" s:NetrwLocalRmFile: remove file fname given the path {{{2
11426" Give confirmation prompt unless all==1
11427fun! s:NetrwLocalRmFile(path,fname,all)
11428" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011429
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430 let all= a:all
11431 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011432 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011433 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11434" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011435
11436 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11437 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011438" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439 if !all
11440 echohl Statement
11441 call inputsave()
11442 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11443 call inputrestore()
11444 echohl NONE
11445 if ok == ""
11446 let ok="no"
11447 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011448" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011449 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011451 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 let all= 1
11453 endif
11454 endif
11455
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011456 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011457 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011458" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011459 endif
11460
11461 else
11462 " attempt to remove directory
11463 if !all
11464 echohl Statement
11465 call inputsave()
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011466 let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011467 call inputrestore()
11468 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11469 if ok == ""
11470 let ok="no"
11471 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011472 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011473 let all= 1
11474 endif
11475 endif
11476 let rmfile= substitute(rmfile,'[\/]$','','e')
11477
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011478 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011479 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011480 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011481 endif
11482 endif
11483 endif
11484
11485" call Dret("s:NetrwLocalRmFile ".ok)
11486 return ok
11487endfun
11488
Bram Moolenaar85850f32019-07-19 22:05:51 +020011489" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011490" Support Functions: {{{1
11491
Bram Moolenaar488c6512005-08-11 20:09:58 +000011492" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011493" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11494" 0: marked file list of current buffer
11495" 1: marked file target
11496fun! netrw#Access(ilist)
11497 if a:ilist == 0
11498 if exists("s:netrwmarkfilelist_".bufnr('%'))
11499 return s:netrwmarkfilelist_{bufnr('%')}
11500 else
11501 return "no-list-buf#".bufnr('%')
11502 endif
11503 elseif a:ilist == 1
11504 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011505 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011506endfun
11507
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011508" ---------------------------------------------------------------------
11509" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11510fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011511 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011512endfun
11513
Bram Moolenaara6878372014-03-22 21:02:50 +010011514" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011515" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11516" I expect this function to be used in
11517" :PChkAssert netrw#Expose("netrwmarkfilelist")
11518" for example.
11519fun! netrw#Expose(varname)
11520" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011521 if exists("s:".a:varname)
11522 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011523" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011524 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011525" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011526 if type(retval) == 3
11527 let retval = copy(retval)
11528 let i = 0
11529 while i < len(retval)
11530 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11531 let i = i + 1
11532 endwhile
11533 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011534" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011535 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011536 else
11537" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011538 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011539 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011540" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011541 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011542 endif
11543
11544" call Dret("netrw#Expose ".string(retval))
11545 return retval
11546endfun
11547
11548" ---------------------------------------------------------------------
11549" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11550fun! netrw#Modify(varname,newvalue)
11551" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11552 exe "let s:".a:varname."= ".string(a:newvalue)
11553" call Dret("netrw#Modify")
11554endfun
11555
11556" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011557" netrw#RFC2396: converts %xx into characters {{{2
11558fun! netrw#RFC2396(fname)
11559" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011560 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011561" call Dret("netrw#RFC2396 ".fname)
11562 return fname
11563endfun
11564
11565" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011566" netrw#UserMaps: supports user-specified maps {{{2
11567" see :help function()
11568"
11569" g:Netrw_UserMaps is a List with members such as:
11570" [[keymap sequence, function reference],...]
11571"
11572" The referenced function may return a string,
11573" refresh : refresh the display
11574" -other- : this string will be executed
11575" or it may return a List of strings.
11576"
11577" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011578" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011579" Related functions:
11580" netrw#Expose(varname) -- see s:varname variables
11581" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11582" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11583fun! netrw#UserMaps(islocal)
11584" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11585" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11586
11587 " set up usermaplist
11588 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11589" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11590 for umap in g:Netrw_UserMaps
11591" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11592" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11593 " if umap[0] is a string and umap[1] is a string holding a function name
11594 if type(umap[0]) == 1 && type(umap[1]) == 1
11595" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11596 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11597 else
11598 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11599 endif
11600 endfor
11601 endif
11602" call Dret("netrw#UserMaps")
11603endfun
11604
11605" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011606" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11607fun! netrw#WinPath(path)
11608" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011609 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011610 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011611 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011612 " remove trailing slash (Win95)
11613 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11614 " remove escaped spaces
11615 let path = substitute(path, '\ ', ' ', 'g')
11616 " convert slashes to backslashes
11617 let path = substitute(path, '/', '\', 'g')
11618 else
11619 let path= a:path
11620 endif
11621" call Dret("netrw#WinPath <".path.">")
11622 return path
11623endfun
11624
11625" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011626" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11627" cb : bl2mf=0 add marked files to buffer list
11628" cB : bl2mf=1 use bufferlist to mark files
11629" (mnemonic: cb = copy (marked files) to buffer list)
11630fun! s:NetrwBadd(islocal,bl2mf)
11631" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11632 if a:bl2mf
11633 " cB: add buffer list to marked files
11634 redir => bufl
11635 ls
11636 redir END
11637 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11638 for fname in bufl
11639 call s:NetrwMarkFile(a:islocal,fname)
11640 endfor
11641 else
11642 " cb: add marked files to buffer list
11643 for fname in s:netrwmarkfilelist_{bufnr("%")}
11644" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11645 exe "badd ".fnameescape(fname)
11646 endfor
11647 let curbufnr = bufnr("%")
11648 let curdir = s:NetrwGetCurdir(a:islocal)
11649 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11650 endif
11651" call Dret("s:NetrwBadd")
11652endfun
11653
11654" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011655" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11656fun! s:ComposePath(base,subdir)
11657" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11658
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011659 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011660" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011661 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011662 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011663 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011664 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011665 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011666 endif
11667
Bram Moolenaar85850f32019-07-19 22:05:51 +020011668 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011669 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011670" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011671 let ret= a:subdir
11672
Nir Lichtman1e34b952024-05-08 19:19:34 +020011673 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011674" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011675 if a:base =~ '[/\\]$'
11676 let ret= a:base.a:subdir
11677 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011678 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011679 endif
11680
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011681 elseif a:base =~ '^\a\{3,}://'
11682" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011683 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11684 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11685 if a:subdir == '../'
11686 if curpath =~ '[^/]/[^/]\+/$'
11687 let curpath= substitute(curpath,'[^/]\+/$','','')
11688 else
11689 let curpath=""
11690 endif
11691 let ret= urlbase.curpath
11692 else
11693 let ret= urlbase.curpath.a:subdir
11694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011695" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11696" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11697" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011698
11699 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011701 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11702 if a:base =~ '^//'
11703 " keeping initial '//' for the benefit of network share listing support
11704 let ret= '/'.ret
11705 endif
11706 let ret= simplify(ret)
11707 endif
11708
11709" call Dret("s:ComposePath ".ret)
11710 return ret
11711endfun
11712
11713" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011714" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11715" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11716fun! s:DeleteBookmark(fname)
11717" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11718 call s:MergeBookmarks()
11719
11720 if exists("g:netrw_bookmarklist")
11721 let indx= index(g:netrw_bookmarklist,a:fname)
11722 if indx == -1
11723 let indx= 0
11724 while indx < len(g:netrw_bookmarklist)
11725 if g:netrw_bookmarklist[indx] =~ a:fname
11726 call remove(g:netrw_bookmarklist,indx)
11727 let indx= indx - 1
11728 endif
11729 let indx= indx + 1
11730 endwhile
11731 else
11732 " remove exact match
11733 call remove(g:netrw_bookmarklist,indx)
11734 endif
11735 endif
11736
11737" call Dret("s:DeleteBookmark")
11738endfun
11739
11740" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011741" s:FileReadable: o/s independent filereadable {{{2
11742fun! s:FileReadable(fname)
11743" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11744
11745 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011746 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011747 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011748 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011749 endif
11750
11751" call Dret("s:FileReadable ".ret)
11752 return ret
11753endfun
11754
11755" ---------------------------------------------------------------------
11756" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11757" Places correct suffix on end of temporary filename,
11758" using the suffix provided with fname
11759fun! s:GetTempfile(fname)
11760" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11761
11762 if !exists("b:netrw_tmpfile")
11763 " get a brand new temporary filename
11764 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011766
Bram Moolenaarc236c162008-07-13 17:41:49 +000011767 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011768" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011769
Bram Moolenaar9964e462007-05-05 17:54:07 +000011770 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011771 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11772" 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 +010011773 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011774" call Dret("s:GetTempfile getcwd<".getcwd().">")
11775 return ""
11776 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011777
Bram Moolenaar9964e462007-05-05 17:54:07 +000011778 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011779 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011780" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011781
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011784 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011785 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011786 if !exists("+shellslash") || !&ssl
11787 let tmpfile = substitute(tmpfile,'/','\','g')
11788 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011789 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011790 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011791 endif
11792 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011793" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 else
11795 " re-use temporary filename
11796 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011798 endif
11799
11800 " use fname's suffix for the temporary file
11801 if a:fname != ""
11802 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011803" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011804 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011806 elseif a:fname =~ '.txz$'
11807 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 else
11809 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11810 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011811" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011813" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11817 endif
11818 endif
11819
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011820" 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 +000011821" call Dret("s:GetTempfile <".tmpfile.">")
11822 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011823endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824
11825" ---------------------------------------------------------------------
11826" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011827" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011829" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011830 if s:user == ""
11831 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11832 else
11833 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11834 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011836 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011837 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011838 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839 else
11840 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11841 endif
11842" call Dret("s:MakeSshCmd <".sshcmd.">")
11843 return sshcmd
11844endfun
11845
11846" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011847" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11848fun! s:MakeBookmark(fname)
11849" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11850
11851 if !exists("g:netrw_bookmarklist")
11852 let g:netrw_bookmarklist= []
11853 endif
11854
11855 if index(g:netrw_bookmarklist,a:fname) == -1
11856 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011857 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011858 call add(g:netrw_bookmarklist,a:fname.'/')
11859 elseif a:fname !~ '/'
11860 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11861 else
11862 call add(g:netrw_bookmarklist,a:fname)
11863 endif
11864 call sort(g:netrw_bookmarklist)
11865 endif
11866
11867" call Dret("s:MakeBookmark")
11868endfun
11869
11870" ---------------------------------------------------------------------
11871" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11872fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011874 " get bookmarks from .netrwbook file
11875 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011876 if filereadable(s:NetrwFile(savefile))
11877" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011878 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011879" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011880 NetrwKeepj call delete(savefile)
11881 endif
11882" call Dret("s:MergeBookmarks")
11883endfun
11884
11885" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011886" s:NetrwBMShow: {{{2
11887fun! s:NetrwBMShow()
11888" call Dfunc("s:NetrwBMShow()")
11889 redir => bmshowraw
11890 menu
11891 redir END
11892 let bmshowlist = split(bmshowraw,'\n')
11893 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011894 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011895 if bmshowfuncs != []
11896 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011897 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011898 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011899 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011901 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011902" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11903endfun
11904
11905" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011906" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011907fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011908 if !exists("w:netrw_liststyle")
11909 let w:netrw_liststyle= g:netrw_liststyle
11910 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011911" 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 +020011912
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011913" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11914
Bram Moolenaaradc21822011-04-01 18:03:16 +020011915 if &ft != "netrw"
11916 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11917 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011918" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011919
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011920 elseif g:netrw_cursor == 8
11921 if w:netrw_liststyle == s:WIDELIST
11922 setl cursorline
11923 setl cursorcolumn
11924 else
11925 setl cursorline
11926 endif
11927 elseif g:netrw_cursor == 7
11928 setl cursorline
11929 elseif g:netrw_cursor == 6
11930 if w:netrw_liststyle == s:WIDELIST
11931 setl cursorline
11932 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011933 elseif g:netrw_cursor == 4
11934 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011935" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011936 setl cursorline
11937 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938
11939 elseif g:netrw_cursor == 3
11940 " thin-long-tree: cursorline, user's cursorcolumn
11941 " wide : cursorline, cursorcolumn
11942 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011943" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011944 setl cursorline
11945 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011946 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011947" 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 +020011948 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011949 endif
11950
11951 elseif g:netrw_cursor == 2
11952 " thin-long-tree: cursorline, user's cursorcolumn
11953 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011955 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011956
11957 elseif g:netrw_cursor == 1
11958 " thin-long-tree: user's cursorline, user's cursorcolumn
11959 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011960 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011962 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011963 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011964" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011965 endif
11966
11967 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011970 let &l:cursorline = s:netrw_usercul
11971 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011972 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011973
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011974" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011976endfun
11977
11978" ---------------------------------------------------------------------
11979" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11980fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011981" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 if exists("s:netrw_usercul")
11983 let &l:cursorline = s:netrw_usercul
11984 endif
11985 if exists("s:netrw_usercuc")
11986 let &l:cursorcolumn = s:netrw_usercuc
11987 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011988" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011989" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11990endfun
11991
11992" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011993" s:NetrwDelete: Deletes a file. {{{2
11994" Uses Steve Hall's idea to insure that Windows paths stay
11995" acceptable. No effect on Unix paths.
11996" Examples of use: let result= s:NetrwDelete(path)
11997fun! s:NetrwDelete(path)
11998" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11999
Bram Moolenaar5c736222010-01-06 20:54:52 +010012000 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012001 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012002 if exists("+shellslash")
12003 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012004 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012005 let result = delete(path)
12006 let &shellslash = sskeep
12007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012008" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012009 let result= delete(path)
12010 endif
12011 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012012" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012013 let result= delete(path)
12014 endif
12015 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012016 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012017 endif
12018
12019" call Dret("s:NetrwDelete ".result)
12020 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012021endfun
12022
12023" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012024" s:NetrwBufRemover: removes a buffer that: {{{2s
12025" has buffer-id > 1
12026" is unlisted
12027" is unnamed
12028" does not appear in any window
12029fun! s:NetrwBufRemover(bufid)
12030" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12031" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12032" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12033" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12034" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12035
yasuda4dbb2662023-10-04 20:50:35 +020012036 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012037" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012038 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012039 endif
12040
12041" call Dret("s:NetrwBufRemover")
12042endfun
12043
12044" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012045" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012046fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012047" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012048" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012049
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012050 " Clean out the last buffer:
12051 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12052 " If so, delete it.
12053 call s:NetrwBufRemover(bufnr("$"))
12054
Bram Moolenaar446cb832008-06-24 21:56:24 +000012055 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012056" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012057 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12058 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12059 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12060 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12061 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12062 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12063 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12064 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12065 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12066 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12067 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12068 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12069 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12070 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12071 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12072 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12073
Bram Moolenaar85850f32019-07-19 22:05:51 +020012074 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012075" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012076 " when tree listing uses file TreeListing... a new buffer is made.
12077 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012078 " COMBAK: this causes a problem, see P43
12079" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012080 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012081 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012082 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012083" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012084 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012085
Bram Moolenaar446cb832008-06-24 21:56:24 +000012086 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012087" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012088 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12089 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12090 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12091 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12092 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12093 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12094 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12095 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12096 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12097 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12098 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12099 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12100 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12101 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12102 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12103 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12104
Bram Moolenaar5c736222010-01-06 20:54:52 +010012105 if a:0 > 0
12106 let b:netrw_curdir= a:1
12107 if b:netrw_curdir =~ '/$'
12108 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012109 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012110 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012111 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012112 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12113 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012114 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012115 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012116 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012117 endif
12118 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012119 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12120 let &l:bexpr = "netrw#BalloonHelp()"
12121 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012122
Bram Moolenaar8d043172014-01-23 14:24:41 +010012123" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012124endfun
12125
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012126" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012127" s:NetrwExe: executes a string using "!" {{{2
12128fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012129" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012130 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012131" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012132 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12133 set shell& shellcmdflag& shellxquote& shellxescape&
12134 set shellquote& shellpipe& shellredir& shellslash&
12135 exe a:cmd
12136 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12137 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012138" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012139 exe a:cmd
12140 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012141 if v:shell_error
12142 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12143 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012144" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012145endfun
12146
12147" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012148" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12149fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012150 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012151" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012152 let curbuf = bufnr("%")
12153 let curwin = winnr()
12154 let iwin = 1
12155 while iwin <= winnr("$")
12156 exe iwin."wincmd w"
12157 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12158 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12159 let winvars= w:
12160 break
12161 endif
12162 let iwin= iwin + 1
12163 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012164 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012165 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012166" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012167 for k in keys(winvars)
12168 let w:{k}= winvars[k]
12169 endfor
12170 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012171" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012172 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012173endfun
12174
Bram Moolenaara6878372014-03-22 21:02:50 +010012175" ---------------------------------------------------------------------
12176" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012177" Returns: 0=success
12178" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012179fun! s:NetrwLcd(newdir)
12180" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012181" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012182
Bram Moolenaar85850f32019-07-19 22:05:51 +020012183 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012184 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012185 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012186 catch /^Vim\%((\a\+)\)\=:E344/
12187 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12188 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012189 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012190 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12191 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012192 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012193 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12194 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012195 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012196 endif
12197 endif
12198 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012199 let err472= 1
12200 endtry
12201
12202 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012203 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12204 if exists("w:netrw_prvdir")
12205 let a:newdir= w:netrw_prvdir
12206 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012207 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012208" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012209 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012210" 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 +010012211 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012212 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012213" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12214 return -1
12215 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012216
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012217" call Decho("getcwd <".getcwd().">")
12218" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012219" call Dret("s:NetrwLcd 0")
12220 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012221endfun
12222
Bram Moolenaar9964e462007-05-05 17:54:07 +000012223" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012224" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12225" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12226fun! s:NetrwSaveWordPosn()
12227" call Dfunc("NetrwSaveWordPosn()")
12228 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12229" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12230endfun
12231
12232" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012233" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12234" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12235fun! s:NetrwHumanReadable(sz)
12236" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12237
12238 if g:netrw_sizestyle == 'h'
12239 if a:sz >= 1000000000
12240 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12241 elseif a:sz >= 10000000
12242 let sz = printf("%d",a:sz/1000000)."m"
12243 elseif a:sz >= 1000000
12244 let sz = printf("%.1f",a:sz/1000000.0)."m"
12245 elseif a:sz >= 10000
12246 let sz = printf("%d",a:sz/1000)."k"
12247 elseif a:sz >= 1000
12248 let sz = printf("%.1f",a:sz/1000.0)."k"
12249 else
12250 let sz= a:sz
12251 endif
12252
12253 elseif g:netrw_sizestyle == 'H'
12254 if a:sz >= 1073741824
12255 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12256 elseif a:sz >= 10485760
12257 let sz = printf("%d",a:sz/1048576)."M"
12258 elseif a:sz >= 1048576
12259 let sz = printf("%.1f",a:sz/1048576.0)."M"
12260 elseif a:sz >= 10240
12261 let sz = printf("%d",a:sz/1024)."K"
12262 elseif a:sz >= 1024
12263 let sz = printf("%.1f",a:sz/1024.0)."K"
12264 else
12265 let sz= a:sz
12266 endif
12267
12268 else
12269 let sz= a:sz
12270 endif
12271
12272" call Dret("s:NetrwHumanReadable ".sz)
12273 return sz
12274endfun
12275
12276" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012277" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12278" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12279fun! s:NetrwRestoreWordPosn()
12280" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012281 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012282" call Dret("NetrwRestoreWordPosn")
12283endfun
12284
12285" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012286" s:RestoreBufVars: {{{2
12287fun! s:RestoreBufVars()
12288" call Dfunc("s:RestoreBufVars()")
12289
12290 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12291 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12292 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12293 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12294 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12295 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12296
12297" call Dret("s:RestoreBufVars")
12298endfun
12299
12300" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012301" s:RemotePathAnalysis: {{{2
12302fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012303" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012304
Bram Moolenaara6878372014-03-22 21:02:50 +010012305 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012306 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012307 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012308 let s:user = substitute(a:dirname,dirpat,'\3','')
12309 let s:machine = substitute(a:dirname,dirpat,'\4','')
12310 let s:port = substitute(a:dirname,dirpat,'\5','')
12311 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012312 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012313 if s:machine =~ '@'
12314 let dirpat = '^\(.*\)@\(.\{-}\)$'
12315 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12316 let s:machine = substitute(s:machine,dirpat,'\2','')
12317 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012318
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012319" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12320" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12321" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12322" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12323" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12324" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012325
12326" call Dret("s:RemotePathAnalysis")
12327endfun
12328
12329" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012330" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12331" Returns status
12332" Runs system() on
12333" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012334" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012335fun! s:RemoteSystem(cmd)
12336" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12337 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012338 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 +000012339 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012340 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012341 else
12342 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12343 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12344 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012346 else
12347 let cmd= cmd.' '
12348 endif
12349 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012350" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012351 let ret= system(cmd)
12352 endif
12353" call Dret("s:RemoteSystem ".ret)
12354 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012355endfun
12356
12357" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012358" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012359fun! s:RestoreWinVars()
12360" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012361 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012362 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12363 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12364 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12365 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12366 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12367 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12368 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12369 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12370 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12371 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12372 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12373 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012374 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12375 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012376 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12377 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12378 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12379" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012380endfun
12381
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012382" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012383" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12384"
12385" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12386" is true) and a command, :Rexplore, which call this function.
12387"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012388" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012389"
12390" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012391fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012392 if exists("s:netrwdrag")
12393 return
12394 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012395" 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 +010012396" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12397" 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 +010012398
12399 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012400 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012401" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012402 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012403 unlet w:netrw_rexfile
12404" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012405 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012406" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012407" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12408" 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 +020012409 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012410
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012411 " ---------------------------
12412 " :Rex issued while in a file
12413 " ---------------------------
12414
Bram Moolenaara6878372014-03-22 21:02:50 +010012415 " record current file so :Rex can return to it from netrw
12416 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012417" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012418
12419 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012420" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012421 return
12422 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012423" 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 +020012424 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012425 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012426 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012428 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012429 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012430 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012431 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012432 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012433" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12434 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012435" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12436 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012437 if exists("s:rexposn_".bufnr('%'))
12438 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012439 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012440 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012441" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012442 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012443
Bram Moolenaar85850f32019-07-19 22:05:51 +020012444 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12445 if exists("s:explore_match")
12446 exe "2match netrwMarkFile /".s:explore_match."/"
12447 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012448 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012449
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012450" 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 +010012451" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012452endfun
12453
12454" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012455" s:SaveBufVars: save selected b: variables to s: variables {{{2
12456" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012457fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012458" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012459
12460 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12461 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12462 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12463 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12464 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12465 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12466
12467" call Dret("s:SaveBufVars")
12468endfun
12469
12470" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012471" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12472fun! s:SavePosn(posndict)
12473" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12474
Bram Moolenaar85850f32019-07-19 22:05:51 +020012475 if !exists("a:posndict[bufnr('%')]")
12476 let a:posndict[bufnr("%")]= []
12477 endif
12478" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12479 call add(a:posndict[bufnr("%")],winsaveview())
12480" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012481
12482" call Dret("s:SavePosn posndict")
12483 return a:posndict
12484endfun
12485
12486" ---------------------------------------------------------------------
12487" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12488fun! s:RestorePosn(posndict)
12489" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012490 if exists("a:posndict")
12491 if has_key(a:posndict,bufnr("%"))
12492" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12493 let posnlen= len(a:posndict[bufnr("%")])
12494 if posnlen > 0
12495 let posnlen= posnlen - 1
12496" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12497 call winrestview(a:posndict[bufnr("%")][posnlen])
12498 call remove(a:posndict[bufnr("%")],posnlen)
12499" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12500 endif
12501 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012502 endif
12503" call Dret("s:RestorePosn")
12504endfun
12505
12506" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012507" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012508fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012509" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012510 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12511 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12512 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12513 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12514 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12515 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12516 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12517 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12518 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12519 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12520 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12521 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12522 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12523 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12524 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12525 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12526 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12527 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12528" call Dret("s:SaveWinVars")
12529endfun
12530
12531" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012532" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012533" To allow separate windows to have their own activities, such as
12534" Explore **/pattern, several variables have been made window-oriented.
12535" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012536" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012537" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012538fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012539" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012540 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12541 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12542 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12543 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12544 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12545 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12546 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12547 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12548 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12549 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12550" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012551endfun
12552
12553" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012554" s:SetRexDir: set directory for :Rexplore {{{2
12555fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012556" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012557 let w:netrw_rexdir = a:dirname
12558 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012559 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012560" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12561" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012562" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012563" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012564" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012565endfun
12566
12567" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012568" s:ShowLink: used to modify thin and tree listings to show links {{{2
12569fun! s:ShowLink()
12570" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012571" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12572" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012573 if exists("b:netrw_curdir")
12574 norm! $?\a
12575 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12576 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012577" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12578" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12579" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12580 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012581 let dirlen = strlen(b:netrw_curdir)
12582 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012583" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012584 endif
12585 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012586" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12587" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012588 setl noro ma
12589 call setline(".",modline)
12590 setl ro noma nomod
12591 endif
12592" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12593endfun
12594
12595" ---------------------------------------------------------------------
12596" s:ShowStyle: {{{2
12597fun! s:ShowStyle()
12598 if !exists("w:netrw_liststyle")
12599 let liststyle= g:netrw_liststyle
12600 else
12601 let liststyle= w:netrw_liststyle
12602 endif
12603 if liststyle == s:THINLIST
12604 return s:THINLIST.":thin"
12605 elseif liststyle == s:LONGLIST
12606 return s:LONGLIST.":long"
12607 elseif liststyle == s:WIDELIST
12608 return s:WIDELIST.":wide"
12609 elseif liststyle == s:TREELIST
12610 return s:TREELIST.":tree"
12611 else
12612 return 'n/a'
12613 endif
12614endfun
12615
12616" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012617" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12618" Solution from Nicolai Weibull, vim docs (:help strlen()),
12619" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012620fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012621" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12622
12623 if v:version >= 703 && exists("*strdisplaywidth")
12624 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012625
Bram Moolenaar8d043172014-01-23 14:24:41 +010012626 elseif type(g:Align_xstrlen) == 1
12627 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12628 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012629
Bram Moolenaar8d043172014-01-23 14:24:41 +010012630 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012631 " number of codepoints (Latin a + combining circumflex is two codepoints)
12632 " (comment from TM, solution from NW)
12633 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012634
Bram Moolenaar8d043172014-01-23 14:24:41 +010012635 elseif g:Align_xstrlen == 2
12636 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012637 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12638 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012639 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012640
Bram Moolenaar8d043172014-01-23 14:24:41 +010012641 elseif g:Align_xstrlen == 3
12642 " virtual length (counting, for instance, tabs as anything between 1 and
12643 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012644 " preceded by lam, one otherwise, etc.)
12645 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646 let modkeep= &l:mod
12647 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012648 call setline(line("."),a:x)
12649 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012651 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012653
Bram Moolenaar446cb832008-06-24 21:56:24 +000012654 else
12655 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012658" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012659 return ret
12660endfun
12661
12662" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012663" s:ShellEscape: shellescape(), or special windows handling {{{2
12664fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012665 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012666 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12667 endif
12668 let f = a:0 > 0 ? a:1 : 0
12669 return shellescape(a:s, f)
12670endfun
12671
12672" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012673" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012674fun! s:TreeListMove(dir)
12675" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012676 let curline = getline('.')
12677 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12678 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12679 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12680 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12681 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12682 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12683" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12684" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12685" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12686" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12687" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12688 " COMBAK : need to handle when on a directory
12689 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012690 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012691 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012692 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012693 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012694" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012695 elseif a:dir == '[]' && nxtline != ''
12696 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012697" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012698 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12699 if nl != 0
12700 NetrwKeepj norm! k
12701 else
12702 NetrwKeepj norm! G
12703 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012704" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012705 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012706 endif
12707
12708" call Dret("s:TreeListMove")
12709endfun
12710
12711" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012712" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12713" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12714" can't be called except via emenu. But due to locale, that menu line may not be called
12715" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12716fun! s:UpdateBuffersMenu()
12717" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012718 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012719 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012720 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012721 catch /^Vim\%((\a\+)\)\=:E/
12722 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012723 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012724 endtry
12725 endif
12726" call Dret("s:UpdateBuffersMenu")
12727endfun
12728
12729" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012730" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012731" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012732fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012733" call Dfunc("s:UseBufWinVars()")
12734 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012735 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12736 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12737 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12738 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12739 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12740 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12741 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12742 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12743 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 +000012744" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012745endfun
12746
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012747" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012748" s:UserMaps: supports user-defined UserMaps {{{2
12749" * calls a user-supplied funcref(islocal,curdir)
12750" * interprets result
12751" See netrw#UserMaps()
12752fun! s:UserMaps(islocal,funcname)
12753" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12754
12755 if !exists("b:netrw_curdir")
12756 let b:netrw_curdir= getcwd()
12757 endif
12758 let Funcref = function(a:funcname)
12759 let result = Funcref(a:islocal)
12760
12761 if type(result) == 1
12762 " if result from user's funcref is a string...
12763" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12764 if result == "refresh"
12765" call Decho("refreshing display",'~'.expand("<slnum>"))
12766 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12767 elseif result != ""
12768" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12769 exe result
12770 endif
12771
12772 elseif type(result) == 3
12773 " if result from user's funcref is a List...
12774" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12775 for action in result
12776 if action == "refresh"
12777" call Decho("refreshing display",'~'.expand("<slnum>"))
12778 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12779 elseif action != ""
12780" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12781 exe action
12782 endif
12783 endfor
12784 endif
12785
12786" call Dret("s:UserMaps")
12787endfun
12788
Bram Moolenaar85850f32019-07-19 22:05:51 +020012789" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012790" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012791" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012792let &cpo= s:keepcpo
12793unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012794
Bram Moolenaar85850f32019-07-19 22:05:51 +020012795" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012796" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012797" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012798" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012799" doing autoload/netrw.vim version v172g ~57
12800" varname<g:netrw_dirhistcnt> value=0 ~1
12801" varname<s:THINLIST> value=0 ~1
12802" varname<s:LONGLIST> value=1 ~1
12803" varname<s:WIDELIST> value=2 ~1
12804" varname<s:TREELIST> value=3 ~1
12805" varname<s:MAXLIST> value=4 ~1
12806" varname<g:netrw_use_errorwindow> value=2 ~1
12807" varname<g:netrw_http_xcmd> value=-q -O ~1
12808" varname<g:netrw_http_put_cmd> value=curl -T ~1
12809" varname<g:netrw_keepj> value=keepj ~1
12810" varname<g:netrw_rcp_cmd> value=rcp ~1
12811" varname<g:netrw_rsync_cmd> value=rsync ~1
12812" varname<g:netrw_rsync_sep> value=/ ~1
12813" varname<g:netrw_scp_cmd> value=scp -q ~1
12814" varname<g:netrw_sftp_cmd> value=sftp ~1
12815" varname<g:netrw_ssh_cmd> value=ssh ~1
12816" varname<g:netrw_alto> value=0 ~1
12817" varname<g:netrw_altv> value=1 ~1
12818" varname<g:netrw_banner> value=1 ~1
12819" varname<g:netrw_browse_split> value=0 ~1
12820" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12821" varname<g:netrw_chgwin> value=-1 ~1
12822" varname<g:netrw_clipboard> value=1 ~1
12823" varname<g:netrw_compress> value=gzip ~1
12824" varname<g:netrw_ctags> value=ctags ~1
12825" varname<g:netrw_cursor> value=2 ~1
12826" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12827" varname<g:netrw_cygdrive> value=/cygdrive ~1
12828" varname<s:didstarstar> value=0 ~1
12829" varname<g:netrw_dirhistcnt> value=0 ~1
12830" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12831" varname<g:netrw_dirhistmax> value=10 ~1
12832" varname<g:netrw_errorlvl> value=0 ~1
12833" varname<g:netrw_fastbrowse> value=1 ~1
12834" varname<g:netrw_ftp_browse_reject> value=^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$ ~1
12835" varname<g:netrw_ftpmode> value=binary ~1
12836" varname<g:netrw_hide> value=1 ~1
12837" varname<g:netrw_keepdir> value=1 ~1
12838" varname<g:netrw_list_hide> value= ~1
12839" varname<g:netrw_localmkdir> value=mkdir ~1
12840" varname<g:netrw_remote_mkdir> value=mkdir ~1
12841" varname<g:netrw_liststyle> value=0 ~1
12842" varname<g:netrw_markfileesc> value=*./[\~ ~1
12843" varname<g:netrw_maxfilenamelen> value=32 ~1
12844" varname<g:netrw_menu> value=1 ~1
12845" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12846" varname<g:netrw_mousemaps> value=1 ~1
12847" varname<g:netrw_retmap> value=0 ~1
12848" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12849" varname<g:netrw_preview> value=0 ~1