blob: b64a1658463f84f3d68cd605541afb9431af502f [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
Travis Sheltone34d0e32024-07-30 21:08:56 +020025" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010026" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000027" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010028" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000029" Permission is hereby granted to use and distribute this code,
30" with or without modifications, provided that this copyright
31" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000032" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000033" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000034" expressed or implied. By using this plugin, you agree that
35" in no event will the copyright holder be liable for any damages
36" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010037"
38" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
39" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
40"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020041"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000042"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000043" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000044" (James 1:22 RSV)
45" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000046" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000047if &cp || exists("g:loaded_netrw")
48 finish
49endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020050
51" Check that vim has patches that netrw requires.
52" Patches needed for v7.4: 1557, and 213.
53" (netrw will benefit from vim's having patch#656, too)
54let s:needspatches=[1557,213]
55if exists("s:needspatches")
56 for ptch in s:needspatches
57 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
58 if !exists("s:needpatch{ptch}")
59 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
60 endif
61 let s:needpatch{ptch}= 1
62 finish
63 endif
64 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020065endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020066
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010067let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000068
Bram Moolenaar1afcace2005-11-25 19:54:28 +000069let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010070setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020071"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010072"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010073"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000075" ======================
76" Netrw Variables: {{{1
77" ======================
78
Bram Moolenaar071d4272004-06-13 20:20:40 +000079" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020080" netrw#ErrorMsg: {{{2
81" 0=note = s:NOTE
82" 1=warning = s:WARNING
83" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010084" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
85" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
86" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010087" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020088fun! netrw#ErrorMsg(level,msg,errnum)
89" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
90
91 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020092" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020093 return
94 endif
95
96 if a:level == 1
97 let level= "**warning** (netrw) "
98 elseif a:level == 2
99 let level= "**error** (netrw) "
100 else
101 let level= "**note** (netrw) "
102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100103" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200104
Damienb4d11642024-08-15 22:00:45 +0200105 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200106 " use popup window
107 if type(a:msg) == 3
108 let msg = [level]+a:msg
109 else
110 let msg= level.a:msg
111 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200112 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200113 let s:popuperr_text= ""
114 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115 " (default) netrw creates a one-line window to show error/warning
116 " messages (reliably displayed)
117
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100118 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200119 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100120" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121
122 " getting messages out reliably is just plain difficult!
123 " This attempt splits the current window, creating a one line window.
124 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100125" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100127" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100129 if type(a:msg) == 3
130 for msg in a:msg
131 NetrwKeepj call setline(line("$")+1,level.msg)
132 endfor
133 else
134 NetrwKeepj call setline(line("$")+1,level.a:msg)
135 endif
136 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100138" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 bo 1split
140 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200141 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100143 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100144" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100146 if type(a:msg) == 3
147 for msg in a:msg
148 NetrwKeepj call setline(line("$")+1,level.msg)
149 endfor
150 else
151 NetrwKeepj call setline(line("$"),level.a:msg)
152 endif
153 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100155" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 if &fo !~ '[ta]'
157 syn clear
158 syn match netrwMesgNote "^\*\*note\*\*"
159 syn match netrwMesgWarning "^\*\*warning\*\*"
160 syn match netrwMesgError "^\*\*error\*\*"
161 hi link netrwMesgWarning WarningMsg
162 hi link netrwMesgError Error
163 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100164" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200165 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200166
167 else
168 " (optional) netrw will show messages using echomsg. Even if the
169 " message doesn't appear, at least it'll be recallable via :messages
170" redraw!
171 if a:level == s:WARNING
172 echohl WarningMsg
173 elseif a:level == s:ERROR
174 echohl Error
175 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100176
177 if type(a:msg) == 3
178 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100179 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100180 endfor
181 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100183 endif
184
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100185" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200186 echohl None
187 endif
188
189" call Dret("netrw#ErrorMsg")
190endfun
191
192" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100193" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100194" Loosely, varname = value.
195fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100196" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100197 if !exists(a:varname)
198 if type(a:value) == 0
199 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200200 elseif type(a:value) == 1 && a:value =~ '^[{[]'
201 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100202 elseif type(a:value) == 1
203 exe "let ".a:varname."="."'".a:value."'"
204 else
205 exe "let ".a:varname."=".a:value
206 endif
207 endif
208endfun
209
210" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000211" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200212call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000213if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100214 call s:NetrwInit("s:THINLIST",0)
215 call s:NetrwInit("s:LONGLIST",1)
216 call s:NetrwInit("s:WIDELIST",2)
217 call s:NetrwInit("s:TREELIST",3)
218 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000219endif
220
Damien7c754112024-08-15 21:58:57 +0200221let s:NOTE = 0
222let s:WARNING = 1
223let s:ERROR = 2
224call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
225
Bram Moolenaar9964e462007-05-05 17:54:07 +0000226" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200227" Default option values: {{{2
228let g:netrw_localcopycmdopt = ""
229let g:netrw_localcopydircmdopt = ""
230let g:netrw_localmkdiropt = ""
231let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200232
233" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000234" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200235if exists("*popup_atcursor")
236\ && has("syntax")
237\ && exists("g:syntax_on")
238\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200239 call s:NetrwInit("g:netrw_use_errorwindow",2)
240else
241 call s:NetrwInit("g:netrw_use_errorwindow",1)
242endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200243
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000244if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100245 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000246 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100247 elseif executable("curl")
248 let g:netrw_dav_cmd = "curl"
249 else
250 let g:netrw_dav_cmd = ""
251 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000253if !exists("g:netrw_fetch_cmd")
254 if executable("fetch")
255 let g:netrw_fetch_cmd = "fetch -o"
256 else
257 let g:netrw_fetch_cmd = ""
258 endif
259endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100260if !exists("g:netrw_file_cmd")
261 if executable("elinks")
262 call s:NetrwInit("g:netrw_file_cmd","elinks")
263 elseif executable("links")
264 call s:NetrwInit("g:netrw_file_cmd","links")
265 endif
266endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000267if !exists("g:netrw_ftp_cmd")
268 let g:netrw_ftp_cmd = "ftp"
269endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200270let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200271if !exists("g:netrw_ftp_options")
272 let g:netrw_ftp_options= "-i -n"
273endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000274if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100275 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100276 let g:netrw_http_cmd = "wget"
277 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100278 elseif executable("curl")
279 let g:netrw_http_cmd = "curl"
280 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200281 elseif executable("elinks")
282 let g:netrw_http_cmd = "elinks"
283 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000284 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100285 let g:netrw_http_cmd = "fetch"
286 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200287 elseif executable("links")
288 let g:netrw_http_cmd = "links"
289 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000290 else
291 let g:netrw_http_cmd = ""
292 endif
293endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100294call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100295call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100296call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
297call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200298call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200299if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200300 if executable("scp")
301 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
302 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200303 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200304 else
305 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
306 endif
307endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100308call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
309call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000310
Nir Lichtman1e34b952024-05-08 19:19:34 +0200311if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000312 \ && exists("g:netrw_use_nt_rcp")
313 \ && g:netrw_use_nt_rcp
314 \ && executable( $SystemRoot .'/system32/rcp.exe')
315 let s:netrw_has_nt_rcp = 1
316 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000317else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000318 let s:netrw_has_nt_rcp = 0
319 let s:netrw_rcpmode = ''
320endif
321
322" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000323" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000324" Cygwin Detection ------- {{{3
325if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200326 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
327 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000328 else
329 let g:netrw_cygwin= 0
330 endif
331endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000332" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100333call s:NetrwInit("g:netrw_alto" , &sb)
334call s:NetrwInit("g:netrw_altv" , &spr)
335call s:NetrwInit("g:netrw_banner" , 1)
336call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200337call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100338call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200339call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100340call s:NetrwInit("g:netrw_compress" , "gzip")
341call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200342if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
343 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
344 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000345endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200346call s:NetrwInit("g:netrw_cursor" , 2)
347let s:netrw_usercul = &cursorline
348let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200349"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100350call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000351" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200352call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200353call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200354call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100355call s:NetrwInit("g:netrw_dirhistmax" , 10)
356call s:NetrwInit("g:netrw_fastbrowse" , 1)
357call 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 +0000358if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000359 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
360 let g:netrw_ftp_list_cmd = "ls -lF"
361 let g:netrw_ftp_timelist_cmd = "ls -tlF"
362 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000363 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000364 let g:netrw_ftp_list_cmd = "dir"
365 let g:netrw_ftp_timelist_cmd = "dir"
366 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000367 endif
368endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100369call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000370" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100371call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372if !exists("g:netrw_ignorenetrc")
373 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
374 let g:netrw_ignorenetrc= 1
375 else
376 let g:netrw_ignorenetrc= 0
377 endif
378endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100379call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000380if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000381 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100382 if exists("g:netrw_list_cmd_options")
383 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
384 else
385 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
386 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000387 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200388 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100389 if exists("g:netrw_list_cmd_options")
390 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
391 else
392 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
393 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000394 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100395" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000396 let g:netrw_list_cmd= ""
397 endif
398endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100399call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000400" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200401if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200402 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200403 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
404endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100405if !exists("g:netrw_localcmdshell")
406 let g:netrw_localcmdshell= ""
407endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000408if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200409 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000410 if g:netrw_cygwin
411 let g:netrw_localcopycmd= "cp"
412 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000413 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200414 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000415 endif
416 elseif has("unix") || has("macunix")
417 let g:netrw_localcopycmd= "cp"
418 else
419 let g:netrw_localcopycmd= ""
420 endif
421endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100422if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200423 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100424 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200425 let g:netrw_localcopydircmd = "cp"
426 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000428 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200429 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200431 elseif has("unix")
432 let g:netrw_localcopydircmd = "cp"
433 let g:netrw_localcopydircmdopt= " -R"
434 elseif has("macunix")
435 let g:netrw_localcopydircmd = "cp"
436 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100437 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200438 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100439 endif
440endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200441if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100442 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200443 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
444endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200445if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200446 if g:netrw_cygwin
447 call s:NetrwInit("g:netrw_localmkdir","mkdir")
448 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000449 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200450 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200451 endif
452else
453 call s:NetrwInit("g:netrw_localmkdir","mkdir")
454endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200455call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200456if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200457 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200458 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
459endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000460if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200461 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000462 if g:netrw_cygwin
463 let g:netrw_localmovecmd= "mv"
464 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000465 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200466 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000467 endif
468 elseif has("unix") || has("macunix")
469 let g:netrw_localmovecmd= "mv"
470 else
471 let g:netrw_localmovecmd= ""
472 endif
473endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100474" following serves as an example for how to insert a version&patch specific test
475"if v:version < 704 || (v:version == 704 && !has("patch1107"))
476"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100477call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
478" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000479if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000480 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000481endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000482if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000483 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
484endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000485" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
487call s:NetrwInit("g:netrw_maxfilenamelen", 32)
488call s:NetrwInit("g:netrw_menu" , 1)
489call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200490call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100491call s:NetrwInit("g:netrw_retmap" , 0)
492if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
493 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200494elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
496else
497 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000498endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100499call s:NetrwInit("g:netrw_preview" , 0)
500call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100501call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100502call s:NetrwInit("g:netrw_sshport" , "-p")
503call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
504call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
505call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100506call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
507" Default values - q-s ---------- {{{3
508call s:NetrwInit("g:netrw_quickhelp",0)
509let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100510 \ "(create new) %:file d:directory",
511 \ "(windows split&open) o:horz v:vert p:preview",
512 \ "i:style qf:file info O:obtain r:reverse",
513 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
514 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
515 \ "(history) qb:list u:go up U:go down",
516 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100517" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
518call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100519if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
520 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
521else
522 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
523endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
525call s:NetrwInit("g:netrw_sort_options" , "")
526call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000527if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200529 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530 else
531 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000532 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000533endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534call s:NetrwInit("g:netrw_special_syntax" , 0)
535call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200536call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100537call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100538call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000539" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200541if !exists("g:netrw_xstrlen")
542 if exists("g:Align_xstrlen")
543 let g:netrw_xstrlen= g:Align_xstrlen
544 elseif exists("g:drawit_xstrlen")
545 let g:netrw_xstrlen= g:drawit_xstrlen
546 elseif &enc == "latin1" || !has("multi_byte")
547 let g:netrw_xstrlen= 0
548 else
549 let g:netrw_xstrlen= 1
550 endif
551endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200553call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100554call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200555if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000556" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000557" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100558call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200559if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200560 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200561else
Bram Moolenaarff034192013-04-24 18:51:19 +0200562 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200563endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200564call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100565call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
566call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100567if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100568 let s:treedepthstring= "│ "
569else
570 let s:treedepthstring= "| "
571endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200572call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000573
574" BufEnter event ignored by decho when following variable is true
575" Has a side effect that doau BufReadPost doesn't work, so
576" files read by network transfer aren't appropriately highlighted.
577"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578
Bram Moolenaaradc21822011-04-01 18:03:16 +0200579" ======================
580" Netrw Initialization: {{{1
581" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200582if 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 +0100583" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100584 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200585" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100586 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100587 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
588 au VimEnter * let s:initbeval= &beval
589"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100590" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
591" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
592" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
593" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
594" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
595" 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 +0200596endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200597au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200598
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200599if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100600 com! -nargs=* NetrwKeepj keepj <args>
601else
602 let g:netrw_keepj= ""
603 com! -nargs=* NetrwKeepj <args>
604endif
605
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000606" ==============================
607" Netrw Utility Functions: {{{1
608" ==============================
609
Bram Moolenaaradc21822011-04-01 18:03:16 +0200610" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100611" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100612if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100613" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100614 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100615 if &ft != "netrw"
616 return ""
617 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200618 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
619 " popup error window is still showing
620 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
621 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
622 " text under mouse hasn't changed; only close window when it changes
623 call popup_close(s:popuperr_id)
624 unlet s:popuperr_text
625 else
626 let s:popuperr_text= v:beval_text
627 endif
628 let mesg= ""
629 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 +0100630 let mesg= ""
631 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
632 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
633 elseif getline(v:beval_lnum) =~ '^"\s*/'
634 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
635 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100636 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100637 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
638 let mesg = "S: edit sorting sequence"
639 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
640 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
641 elseif v:beval_text == "Quick" || v:beval_text == "Help"
642 let mesg = "Help: press <F1>"
643 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
644 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
645 else
646 let mesg= ""
647 endif
648 return mesg
649 endfun
650"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100651" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
652" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
653" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
654" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
655" 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 +0200656endif
657
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200659" netrw#Explore: launch the local browser in the directory of the current file {{{2
660" indx: == -1: Nexplore
661" == -2: Pexplore
662" == +: this is overloaded:
663" * If Nexplore/Pexplore is in use, then this refers to the
664" indx'th item in the w:netrw_explore_list[] of items which
665" matched the */pattern **/pattern *//pattern **//pattern
666" * If Hexplore or Vexplore, then this will override
667" g:netrw_winsize to specify the qty of rows or columns the
668" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100669" 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 +0200670" dosplit==1: the window will be split before running the local browser
671" style == 0: Explore style == 1: Explore!
672" == 2: Hexplore style == 3: Hexplore!
673" == 4: Vexplore style == 5: Vexplore!
674" == 6: Texplore
675fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100676" 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 +0100677" 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 +0200678 if !exists("b:netrw_curdir")
679 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100680" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200681 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100682
683 " record current file for Rexplore's benefit
684 if &ft != "netrw"
685 let w:netrw_rexfile= expand("%:p")
686 endif
687
688 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200689 let curdir = simplify(b:netrw_curdir)
690 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200691 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200692 let curdir= substitute(curdir,'\','/','g')
693 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100694" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100695
696 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
697 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
698 " try Explore again.
699 if a:0 > 0
700" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100701 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
702 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
703 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
704 \ '~'.expand("<slnum>"))
705 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200706 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
707 if a1 != a:1
708 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
709 return
710 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100711 endif
712 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200713
714 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200715 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100716" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100717 sil! let keepregstar = @*
718 sil! let keepregplus = @+
719 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200720 sil! let keepregslash= @/
721
Bram Moolenaar8d043172014-01-23 14:24:41 +0100722 " if dosplit
723 " -or- file has been modified AND file not hidden when abandoned
724 " -or- Texplore used
725 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200726 call s:SaveWinVars()
727 let winsz= g:netrw_winsize
728 if a:indx > 0
729 let winsz= a:indx
730 endif
731
732 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200734 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200735 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200736
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200737 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200738 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200739 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200740 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200741
742 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200745 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
747 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200750 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 elseif a:style == 4 " Vexplore
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
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200755 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200756
757 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200760 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200761
762 elseif a:style == 6 " Texplore
763 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200764 exe "keepalt tabnew ".fnameescape(curdir)
765 call s:RestoreBufVars()
766 endif
767 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100769 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200770
771 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
780 if dirname !~ '/$'
781 let dirname= dirname."/"
782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.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 ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200788 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let dirname= a:1
795 endif
796 else
797 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 call s:NetrwClearExplore()
800" call Dret("netrw#Explore : cleared list")
801 return
802 endif
803
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100804" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 if dirname =~ '\.\./\=$'
806 let dirname= simplify(fnamemodify(dirname,':p:h'))
807 elseif dirname =~ '\.\.' || dirname == '.'
808 let dirname= simplify(fnamemodify(dirname,':p'))
809 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811
812 if dirname =~ '^\*//'
813 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
816 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100817" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200818 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
819
820 elseif dirname =~ '^\*\*//'
821 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 let pattern= substitute(dirname,'^\*\*//','','')
824 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826
827 elseif dirname =~ '/\*\*/'
828 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200831 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 let b:netrw_curdir = prefixdir
833 else
834 let b:netrw_curdir= getcwd().'/'.prefixdir
835 endif
836 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
837 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100838" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
839" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840
841 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200842 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200843 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100844" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200845
846 elseif dirname=~ '^\*\*/'
847 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
848 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100849" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850
851 else
852 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854 endif
855
856 if starpat == 0 && a:indx >= 0
857 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" 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 +0200859 if dirname == ""
860 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200862 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200863 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200864 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200865 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200866 if dirname == ""
867 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200868 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100869 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100870 " depending on whether backslashes have been converted to forward slashes by earlier code).
871 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200872 let dirname= b:netrw_curdir."/".dirname
873 endif
874 elseif dirname !~ '^/'
875 let dirname= b:netrw_curdir."/".dirname
876 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100877" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200878 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100879" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
880" 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 +0200881 endif
882 if exists("w:netrw_bannercnt")
883 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
884 " If one wants to return the same place in the netrw window, use :Rex instead.
885 exe w:netrw_bannercnt
886 endif
887
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100888" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200889 " ---------------------------------------------------------------------
890 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
891" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100892" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200893" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100894" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200895" endif
896 " ---------------------------------------------------------------------
897
898 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
899 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
900 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
901 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
902 elseif a:indx <= 0
903 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100904" 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 +0200905 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100906" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200907 let s:didstarstar= 1
908 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
909 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
910 endif
911
912 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200914 if !exists("w:netrw_explore_indx")
915 let w:netrw_explore_indx= 0
916 endif
917
918 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100919" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200920
921 if indx == -1
922 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100923" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100925 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 +0200926 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100927" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100928 if @* != keepregstar | sil! let @* = keepregstar | endif
929 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100930 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200931 sil! let @/ = keepregslash
932" call Dret("netrw#Explore")
933 return
934 endif
935 let indx= w:netrw_explore_indx
936 if indx < 0 | let indx= 0 | endif
937 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
938 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100939" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
941 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100942" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 endwhile
944 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100945" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200946
947 elseif indx == -2
948 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100951 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 +0200952 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100953" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100954 if @* != keepregstar | sil! let @* = keepregstar | endif
955 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100956 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200957 sil! let @/ = keepregslash
958" call Dret("netrw#Explore")
959 return
960 endif
961 let indx= w:netrw_explore_indx
962 if indx < 0 | let indx= 0 | endif
963 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
964 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100965" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 while indx >= 0 && curfile == w:netrw_explore_list[indx]
967 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100968" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 endwhile
970 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100971" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972
973 else
974 " Explore -- initialize
975 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100976" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100977 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 let w:netrw_explore_indx= 0
979 if !exists("b:netrw_curdir")
980 let b:netrw_curdir= getcwd()
981 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100982" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200983
984 " switch on starpat to build the w:netrw_explore_list of files
985 if starpat == 1
986 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100987" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
988" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200989 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100990 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200991 catch /^Vim\%((\a\+)\)\=:E480/
992 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
993" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
994 return
995 endtry
996 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
997 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
998
999 elseif starpat == 2
1000 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001001" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1002" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001003 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001004 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001005 catch /^Vim\%((\a\+)\)\=:E480/
1006 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1007 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001008 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001009" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001010 if @* != keepregstar | sil! let @* = keepregstar | endif
1011 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001012 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 sil! let @/ = keepregslash
1014" call Dret("netrw#Explore : no files matched pattern")
1015 return
1016 endtry
1017 let s:netrw_curdir = b:netrw_curdir
1018 let w:netrw_explore_list = getqflist()
1019 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1020 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1021
1022 elseif starpat == 3
1023 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001024" 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 +02001025 let filepat= substitute(dirname,'^\*/','','')
1026 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001027" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1028" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001029 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1030 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1031
1032 elseif starpat == 4
1033 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001034" 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 +02001035 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1036 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1037 endif " switch on starpat to build w:netrw_explore_list
1038
1039 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001040" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1041" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001042
1043 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001044 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001045 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001046" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001047 if @* != keepregstar | sil! let @* = keepregstar | endif
1048 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001049 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001050 sil! let @/ = keepregslash
1051" call Dret("netrw#Explore : no files matched")
1052 return
1053 endif
1054 endif " if indx ... endif
1055
1056 " NetrwStatusLine support - for exploring support
1057 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001058" 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 +02001059
1060 " wrap the indx around, but issue a note
1061 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001062" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001063 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1064 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001065 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001066 endif
1067
1068 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001069" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001071" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 call netrw#LocalBrowseCheck(newdir)
1075 if !exists("w:netrw_liststyle")
1076 let w:netrw_liststyle= g:netrw_liststyle
1077 endif
1078 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001079 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001081 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 endif
1083 let w:netrw_explore_mtchcnt = indx + 1
1084 let w:netrw_explore_bufnr = bufnr("%")
1085 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001086 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001087" 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 +02001088
1089 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001090" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001091 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001092 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 +02001093 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001094 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001095" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001096 if @* != keepregstar | sil! let @* = keepregstar | endif
1097 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001098 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001099 sil! let @/ = keepregslash
1100" call Dret("netrw#Explore : missing +path_extra")
1101 return
1102 endif
1103
1104 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001105" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1107 sil! unlet w:netrw_treedict
1108 sil! unlet w:netrw_treetop
1109 endif
1110 let newdir= dirname
1111 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001112 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001113 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001114 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 endif
1116 endif
1117
1118 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001119" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1120" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001122" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001124 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001125" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 let s:explore_prvdir = b:netrw_curdir
1127 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001128 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 if b:netrw_curdir !~ '/$'
1130 let dirlen= dirlen + 1
1131 endif
1132 let prvfname= ""
1133 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if fname =~ '^'.b:netrw_curdir
1136 if s:explore_match == ""
1137 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1138 else
1139 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1140 endif
1141 elseif fname !~ '^/' && fname != prvfname
1142 if s:explore_match == ""
1143 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1144 else
1145 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1146 endif
1147 endif
1148 let prvfname= fname
1149 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001150" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001151 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1152 exe "2match netrwMarkFile /".s:explore_match."/"
1153 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001154 endif
1155 echo "<s-up>==Pexplore <s-down>==Nexplore"
1156 else
1157 2match none
1158 if exists("s:explore_match") | unlet s:explore_match | endif
1159 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001160" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001161 endif
1162
Bram Moolenaara6878372014-03-22 21:02:50 +01001163 " since Explore may be used to initialize netrw's browser,
1164 " there's no danger of a late FocusGained event on initialization.
1165 " Consequently, set s:netrw_events to 2.
1166 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001167 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001168" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001169 if @* != keepregstar | sil! let @* = keepregstar | endif
1170 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001171 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001172 sil! let @/ = keepregslash
1173" call Dret("netrw#Explore : @/<".@/.">")
1174endfun
1175
1176" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001177" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001178" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1179" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1180" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1181" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1182" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001183fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001184" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185 let curwin= winnr()
1186
Bram Moolenaara6878372014-03-22 21:02:50 +01001187 if a:0 > 0 && a:1 != ""
1188 " if a netrw window is already on the left-side of the tab
1189 " and a directory has been specified, explore with that
1190 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001191" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001193" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001194 exe "1wincmd w"
1195 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001196" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 exe "Explore ".fnameescape(a1)
1198 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001199 let s:lexplore_win= curwin
1200 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 unlet t:netrw_lexposn
1204 endif
1205" call Dret("netrw#Lexplore")
1206 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001207 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 exe curwin."wincmd w"
1209 else
1210 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001211" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001212 endif
1213
Bram Moolenaar8d043172014-01-23 14:24:41 +01001214 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001216 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001217" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 else
1219 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001222" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223
1224 if lexwinnr > 0
1225 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 exe lexwinnr."wincmd w"
1228 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001229 let t:netrw_lexposn = winsaveview()
1230" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001231" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232 close
1233 if lexwinnr < curwin
1234 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001235 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001236 if lexwinnr != curwin
1237 exe curwin."wincmd w"
1238 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001239 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001240" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001241
1242 else
1243 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001244" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245 exe "1wincmd w"
1246 let keep_altv = g:netrw_altv
1247 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001248 if a:count != 0
1249 let netrw_winsize = g:netrw_winsize
1250 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001254 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 +02001255" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001257" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001258 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260 elseif curfile =~ '^\a\{3,}://'
1261" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001262 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001265 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 endif
1267 if a:count != 0
1268 let g:netrw_winsize = netrw_winsize
1269 endif
1270 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001271 let g:netrw_altv = keep_altv
1272 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001273 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1274 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001275 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001276 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001277" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1278" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001279 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001280" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001281" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1282 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001283 unlet t:netrw_lexposn
1284 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001285 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001286
1287 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001288 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289 if a:rightside
1290 let g:netrw_chgwin= 1
1291 else
1292 let g:netrw_chgwin= 2
1293 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001294" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001295 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001296
Bram Moolenaar8d043172014-01-23 14:24:41 +01001297" call Dret("netrw#Lexplore")
1298endfun
1299
1300" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001301" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001302" supports :NetrwClean -- remove netrw from first directory on runtimepath
1303" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001304fun! netrw#Clean(sys)
1305" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001306
1307 if a:sys
1308 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1309 else
1310 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1311 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001312" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001313 let diddel= 0
1314 let diddir= ""
1315
1316 if choice == 1
1317 for dir in split(&rtp,',')
1318 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001319" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001320 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1321 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1322 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1323 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1324 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1325 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 +00001326 let diddir= dir
1327 let diddel= diddel + 1
1328 if !a:sys|break|endif
1329 endif
1330 endfor
1331 endif
1332
1333 echohl WarningMsg
1334 if diddel == 0
1335 echomsg "netrw is either not installed or not removable"
1336 elseif diddel == 1
1337 echomsg "removed one copy of netrw from <".diddir.">"
1338 else
1339 echomsg "removed ".diddel." copies of netrw"
1340 endif
1341 echohl None
1342
Bram Moolenaara6878372014-03-22 21:02:50 +01001343" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001344endfun
1345
Bram Moolenaar5c736222010-01-06 20:54:52 +01001346" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001347" netrw#MakeTgt: make a target out of the directory name provided {{{2
1348fun! netrw#MakeTgt(dname)
1349" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1350 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001351 let svpos = winsaveview()
1352" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001353 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1354" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001355 if s:netrwmftgt_islocal
1356 let netrwmftgt= simplify(a:dname)
1357 else
1358 let netrwmftgt= a:dname
1359 endif
1360 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1361 " re-selected target, so just clear it
1362 unlet s:netrwmftgt s:netrwmftgt_islocal
1363 else
1364 let s:netrwmftgt= netrwmftgt
1365 endif
1366 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001367 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001368 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001369" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1370 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001371" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001372endfun
1373
Bram Moolenaara6878372014-03-22 21:02:50 +01001374" ---------------------------------------------------------------------
1375" netrw#Obtain: {{{2
1376" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001377" islocal=0 obtain from remote source
1378" =1 obtain from local source
1379" fname : a filename or a list of filenames
1380" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001381fun! netrw#Obtain(islocal,fname,...)
1382" 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 +02001383 " NetrwStatusLine support - for obtaining support
1384
1385 if type(a:fname) == 1
1386 let fnamelist= [ a:fname ]
1387 elseif type(a:fname) == 3
1388 let fnamelist= a:fname
1389 else
1390 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 +01001391" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001392 return
1393 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 if a:0 > 0
1396 let tgtdir= a:1
1397 else
1398 let tgtdir= getcwd()
1399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401
1402 if exists("b:netrw_islocal") && b:netrw_islocal
1403 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1406 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001407 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001412 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 if v:shell_error != 0
1414 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 +01001415" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 return
1417 endif
1418 endfor
1419 else
1420 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1422 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1423" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001424 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 if v:shell_error != 0
1426 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 +01001427" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 return
1429 endif
1430 endif
1431 elseif !exists("b:netrw_curdir")
1432 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1433 else
1434 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1435 endif
1436
1437 else
1438 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001439" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001440 if type(a:fname) == 1
1441 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1442 endif
1443 call s:NetrwMethod(b:netrw_curdir)
1444
1445 if b:netrw_method == 4
1446 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001447" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 if exists("g:netrw_port") && g:netrw_port != ""
1449 let useport= " ".g:netrw_scpport." ".g:netrw_port
1450 else
1451 let useport= ""
1452 endif
1453 if b:netrw_fname =~ '/'
1454 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1455 else
1456 let path= ""
1457 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001458 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459 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 +02001460
1461 elseif b:netrw_method == 2
1462 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001464 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001465 let tmpbufnr= bufnr("%")
1466 setl ff=unix
1467 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001468 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001470 endif
1471
1472 if exists("b:netrw_fname") && b:netrw_fname != ""
1473 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001474" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 endif
1476
1477 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001478 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481 for fname in fnamelist
1482 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endfor
1485 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486 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 +02001487 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endif
1490 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1491 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1492 let debugkeep= &debug
1493 setl debug=msg
1494 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1495 let &debug= debugkeep
1496 endif
1497
1498 elseif b:netrw_method == 3
1499 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001501 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001502 let tmpbufnr= bufnr("%")
1503 setl ff=unix
1504
1505 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001506 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001507" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001508 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 endif
1512
1513 if exists("g:netrw_uid") && g:netrw_uid != ""
1514 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001519 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 endif
1525 endif
1526
1527 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001528 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 endif
1531
1532 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001533 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001534" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 endif
1536
1537 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001539" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 endif
1541
1542 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001548 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001550
1551 " perform ftp:
1552 " -i : turns off interactive prompting from ftp
1553 " -n unix : DON'T use <.netrc>, even though it exists
1554 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001555 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1556 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001557 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001558 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1559 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001560" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001561 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001562 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001563 endif
1564 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001565
1566 elseif b:netrw_method == 9
1567 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001568" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001569 if a:fname =~ '/'
1570 let localfile= substitute(a:fname,'^.*/','','')
1571 else
1572 let localfile= a:fname
1573 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001574 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 +02001575
Bram Moolenaarff034192013-04-24 18:51:19 +02001576 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001577 " probably a badly formed url; protocol not recognized
1578" call Dret("netrw#Obtain : unsupported method")
1579 return
1580
1581 else
1582 " protocol recognized but not supported for Obtain (yet?)
1583 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001584 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001585 endif
1586" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001587 return
1588 endif
1589
1590 " restore status line
1591 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001592 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001593 endif
1594
1595 endif
1596
1597 " cleanup
1598 if exists("tmpbufnr")
1599 if bufnr("%") != tmpbufnr
1600 exe tmpbufnr."bw!"
1601 else
1602 q!
1603 endif
1604 endif
1605
Bram Moolenaara6878372014-03-22 21:02:50 +01001606" call Dret("netrw#Obtain")
1607endfun
1608
1609" ---------------------------------------------------------------------
1610" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1611fun! netrw#Nread(mode,fname)
1612" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001613 let svpos= winsaveview()
1614" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001615 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001616" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1617 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001618
1619 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1620 if exists("w:netrw_bannercnt")
1621 " start with cursor just after the banner
1622 exe w:netrw_bannercnt
1623 endif
1624 endif
1625" call Dret("netrw#Nread")
1626endfun
1627
1628" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001629" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1630" Options get restored by s:NetrwOptionsRestore()
1631"
1632" Option handling:
1633" * save user's options (s:NetrwOptionsSave)
1634" * set netrw-safe options (s:NetrwOptionsSafe)
1635" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1636" * restore user's options (s:netrwOPtionsRestore)
1637" - restore a user option when != safe option (s:NetrwRestoreSetting)
1638" vt: (variable type) normally its either "w:" or "s:"
1639fun! s:NetrwOptionsSave(vt)
1640" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1641" 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 +02001642" 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>"))
1643" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001644
1645 if !exists("{a:vt}netrw_optionsave")
1646 let {a:vt}netrw_optionsave= 1
1647 else
1648" call Dret("s:NetrwOptionsSave : options already saved")
1649 return
1650 endif
1651" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1652
1653 " Save current settings and current directory
1654" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1655 let s:yykeep = @@
1656 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1657 let {a:vt}netrw_aikeep = &l:ai
1658 let {a:vt}netrw_awkeep = &l:aw
1659 let {a:vt}netrw_bhkeep = &l:bh
1660 let {a:vt}netrw_blkeep = &l:bl
1661 let {a:vt}netrw_btkeep = &l:bt
1662 let {a:vt}netrw_bombkeep = &l:bomb
1663 let {a:vt}netrw_cedit = &cedit
1664 let {a:vt}netrw_cikeep = &l:ci
1665 let {a:vt}netrw_cinkeep = &l:cin
1666 let {a:vt}netrw_cinokeep = &l:cino
1667 let {a:vt}netrw_comkeep = &l:com
1668 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001669 let {a:vt}netrw_cuckeep = &l:cuc
1670 let {a:vt}netrw_culkeep = &l:cul
1671" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001672 let {a:vt}netrw_diffkeep = &l:diff
1673 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001674 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1675 let {a:vt}netrw_ffkeep = &l:ff
1676 endif
1677 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1678 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001679 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001680 let {a:vt}netrw_hidkeep = &l:hidden
1681 let {a:vt}netrw_imkeep = &l:im
1682 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001683 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_lskeep = &l:ls
1685 let {a:vt}netrw_makeep = &l:ma
1686 let {a:vt}netrw_magickeep = &l:magic
1687 let {a:vt}netrw_modkeep = &l:mod
1688 let {a:vt}netrw_nukeep = &l:nu
1689 let {a:vt}netrw_rnukeep = &l:rnu
1690 let {a:vt}netrw_repkeep = &l:report
1691 let {a:vt}netrw_rokeep = &l:ro
1692 let {a:vt}netrw_selkeep = &l:sel
1693 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001694 if !g:netrw_use_noswf
1695 let {a:vt}netrw_swfkeep = &l:swf
1696 endif
1697 let {a:vt}netrw_tskeep = &l:ts
1698 let {a:vt}netrw_twkeep = &l:tw " textwidth
1699 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1700 let {a:vt}netrw_wrapkeep = &l:wrap
1701 let {a:vt}netrw_writekeep = &l:write
1702
1703 " save a few selected netrw-related variables
1704" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1705 if g:netrw_keepdir
1706 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001707" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001708 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001709 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001710 sil! let {a:vt}netrw_starkeep = @*
1711 sil! let {a:vt}netrw_pluskeep = @+
1712 endif
1713 sil! let {a:vt}netrw_slashkeep= @/
1714
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001715" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001716" 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>"))
1717" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1718endfun
1719
1720" ---------------------------------------------------------------------
1721" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1722" Use s:NetrwSaveOptions() to save user settings
1723" Use s:NetrwOptionsRestore() to restore user settings
1724fun! s:NetrwOptionsSafe(islocal)
1725" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1726" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1727" 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>"))
1728 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1729 call s:NetrwSetSafeSetting("&l:ai",0)
1730 call s:NetrwSetSafeSetting("&l:aw",0)
1731 call s:NetrwSetSafeSetting("&l:bl",0)
1732 call s:NetrwSetSafeSetting("&l:bomb",0)
1733 if a:islocal
1734 call s:NetrwSetSafeSetting("&l:bt","nofile")
1735 else
1736 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1737 endif
1738 call s:NetrwSetSafeSetting("&l:ci",0)
1739 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001740 if g:netrw_fastbrowse > a:islocal
1741 call s:NetrwSetSafeSetting("&l:bh","hide")
1742 else
1743 call s:NetrwSetSafeSetting("&l:bh","delete")
1744 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001745 call s:NetrwSetSafeSetting("&l:cino","")
1746 call s:NetrwSetSafeSetting("&l:com","")
1747 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1748 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1749 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001750 if &go =~ 'a' | set go-=a | endif
1751 if &go =~ 'A' | set go-=A | endif
1752 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001753 call s:NetrwSetSafeSetting("&l:hid",0)
1754 call s:NetrwSetSafeSetting("&l:im",0)
1755 setl isk+=@ isk+=* isk+=/
1756 call s:NetrwSetSafeSetting("&l:magic",1)
1757 if g:netrw_use_noswf
1758 call s:NetrwSetSafeSetting("swf",0)
1759 endif
1760 call s:NetrwSetSafeSetting("&l:report",10000)
1761 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1762 call s:NetrwSetSafeSetting("&l:spell",0)
1763 call s:NetrwSetSafeSetting("&l:tw",0)
1764 call s:NetrwSetSafeSetting("&l:wig","")
1765 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001766
1767 " set up cuc and cul based on g:netrw_cursor and listing style
1768 " COMBAK -- cuc cul related
1769 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001770
1771 " allow the user to override safe options
1772" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1773 if &ft == "netrw"
1774" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1775 keepalt NetrwKeepj doau FileType netrw
1776 endif
1777
1778" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1779" 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>"))
1780" call Dret("s:NetrwOptionsSafe")
1781endfun
1782
1783" ---------------------------------------------------------------------
1784" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1785fun! s:NetrwOptionsRestore(vt)
1786" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001787" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001788" 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 +01001789 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001790" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001791
1792 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1793 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001794" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001795 filetype detect
1796" 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>"))
1797 else
1798 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001799 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001800" 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 +02001801" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001802 return
1803 endif
1804 unlet {a:vt}netrw_optionsave
1805
1806 if exists("+acd")
1807 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001808" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001809 let curdir = getcwd()
1810 let &l:acd = {a:vt}netrw_acdkeep
1811 unlet {a:vt}netrw_acdkeep
1812 if &l:acd
1813 call s:NetrwLcd(curdir)
1814 endif
1815 endif
1816 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001817" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001818 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1819 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1820 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1821 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1822 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001823" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001824 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1825 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1826 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1827 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1828 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001829" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001830 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1831 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1832 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1833 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1834 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001835 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001836" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1837 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1838 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001839 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1841" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1842 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1843 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1844" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1845 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1846" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1847 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1848 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001849 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001850 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1851 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1852" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1853 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1854 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1855 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1856 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1857" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1860 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1861 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001863" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001864 call s:NetrwRestoreSetting("s:yykeep","@@")
1865 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1866 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1867 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1868 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1869
Bram Moolenaara6878372014-03-22 21:02:50 +01001870 if exists("{a:vt}netrw_swfkeep")
1871 if &directory == ""
1872 " user hasn't specified a swapfile directory;
1873 " netrw will temporarily set the swapfile directory
1874 " to the current directory as returned by getcwd().
1875 let &l:directory= getcwd()
1876 sil! let &l:swf = {a:vt}netrw_swfkeep
1877 setl directory=
1878 unlet {a:vt}netrw_swfkeep
1879 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001880 if !g:netrw_use_noswf
1881 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1882 sil! let &l:swf= {a:vt}netrw_swfkeep
1883 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001884 unlet {a:vt}netrw_swfkeep
1885 endif
1886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001887 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001888 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1889 if exists("{a:vt}netrw_dirkeep")
1890 call s:NetrwLcd(dirkeep)
1891 unlet {a:vt}netrw_dirkeep
1892 endif
1893 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001894 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001895" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001896 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1897 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001898 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001899 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001901" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1902" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1903" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1904" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1905" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001906 " Moved the filetype detect here from NetrwGetFile() because remote files
1907 " were having their filetype detect-generated settings overwritten by
1908 " NetrwOptionRestore.
1909 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001910" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1911 filetype detect
1912" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001913 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001914" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001915" 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 +02001916" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001917endfun
1918
1919" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001920" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1921" but only when the options' value and the safe setting differ
1922" Doing this means that netrw will not come up as having changed a
1923" setting last when it really didn't actually change it.
1924"
1925" Called from s:NetrwOptionsSafe
1926" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1927fun! s:NetrwSetSafeSetting(setting,safesetting)
1928" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001929
Bram Moolenaar85850f32019-07-19 22:05:51 +02001930 if a:setting =~ '^&'
1931" call Decho("fyi: a:setting starts with &")
1932 exe "let settingval= ".a:setting
1933" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001934
Bram Moolenaar85850f32019-07-19 22:05:51 +02001935 if settingval != a:safesetting
1936" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1937 if type(a:safesetting) == 0
1938 exe "let ".a:setting."=".a:safesetting
1939 elseif type(a:safesetting) == 1
1940 exe "let ".a:setting."= '".a:safesetting."'"
1941 else
1942 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1943 endif
1944 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001945 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001946
Bram Moolenaar85850f32019-07-19 22:05:51 +02001947" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001948endfun
1949
1950" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001951" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1952" but only if the setting value differs from the associated keepvar.
1953" Doing this means that netrw will not come up as having changed a
1954" setting last when it really didn't actually change it.
1955"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001956" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957" keepvars are set up by s:NetrwOptionsSave
1958fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001959""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001960
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961 " typically called from s:NetrwOptionsRestore
1962 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1963 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001964 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001965 if exists(a:keepvar)
1966 exe "let keepvarval= ".a:keepvar
1967 exe "let setting= ".a:setting
1968
1969"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1970"" call Decho("fyi: keepvarval=".keepvarval)
1971"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1972
1973 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001974"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001975 if type(a:setting) == 0
1976 exe "let ".a:setting."= ".keepvarval
1977 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001978 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001979 else
1980 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1981 endif
1982 endif
1983
1984 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001985 endif
1986
Bram Moolenaar85850f32019-07-19 22:05:51 +02001987"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001988endfun
1989
1990" ---------------------------------------------------------------------
1991" NetrwStatusLine: {{{2
1992fun! NetrwStatusLine()
1993
1994" vvv NetrwStatusLine() debugging vvv
1995" let g:stlmsg=""
1996" if !exists("w:netrw_explore_bufnr")
1997" let g:stlmsg="!X<explore_bufnr>"
1998" elseif w:netrw_explore_bufnr != bufnr("%")
1999" let g:stlmsg="explore_bufnr!=".bufnr("%")
2000" endif
2001" if !exists("w:netrw_explore_line")
2002" let g:stlmsg=" !X<explore_line>"
2003" elseif w:netrw_explore_line != line(".")
2004" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2005" endif
2006" if !exists("w:netrw_explore_list")
2007" let g:stlmsg=" !X<explore_list>"
2008" endif
2009" ^^^ NetrwStatusLine() debugging ^^^
2010
2011 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")
2012 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002013 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002014 let &laststatus = s:netrw_users_ls
2015 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2016 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2017 return ""
2018 else
2019 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2020 endif
2021endfun
2022
Bram Moolenaar85850f32019-07-19 22:05:51 +02002023" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002024" Netrw Transfer Functions: {{{1
2025" ===============================
2026
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002028" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002029" mode: =0 read remote file and insert before current line
2030" =1 read remote file and insert after current line
2031" =2 replace with remote file
2032" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002033fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002034" 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 +00002035
Bram Moolenaar5c736222010-01-06 20:54:52 +01002036 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002037 call s:NetrwOptionsSave("w:")
2038 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002039 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002040 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2041 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2042 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002043" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002044
Bram Moolenaar5c736222010-01-06 20:54:52 +01002045 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002047 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002048 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002049 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050 elseif a:mode == 2 " replace with remote file
2051 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002052 elseif a:mode == 3 " skip read of file (leave as temporary)
2053 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 else
2055 exe a:mode
2056 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002059" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060
Bram Moolenaar5c736222010-01-06 20:54:52 +01002061 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002062 let tmpfile= s:GetTempfile("")
2063 if tmpfile == ""
2064" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002065 return
2066 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002068 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002069
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 " attempt to repeat with previous host-file-etc
2071 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002072" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 let choice = b:netrw_lastfile
2074 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 else
2077 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002078" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002081 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002082 echomsg 'NetRead Usage:'
2083 echomsg ':Nread machine:path uses rcp'
2084 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2085 echomsg ':Nread "machine id password path" uses ftp'
2086 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2087 echomsg ':Nread fetch://machine/path uses fetch'
2088 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2089 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002090 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002091 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002092 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2093 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2094 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2095 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002096 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002097 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002098
Bram Moolenaar9964e462007-05-05 17:54:07 +00002099 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002100 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002101" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002102 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002103 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002104 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 else
2106 " case "... ... ..."
2107 let choice = strpart(choice,1,strlen(choice)-1)
2108 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002109
Bram Moolenaar9964e462007-05-05 17:54:07 +00002110 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 let wholechoice = wholechoice . " " . choice
2112 let ichoice = ichoice + 1
2113 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002114 if !exists("g:netrw_quiet")
2115 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2116 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002117" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002118 return
2119 endif
2120 let choice= a:{ichoice}
2121 endwhile
2122 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2123 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 endif
2125 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002127" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002128 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002129
Bram Moolenaar5c736222010-01-06 20:54:52 +01002130 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002131 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002132 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002133" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002134 return
2135 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002136 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002137
Bram Moolenaar8d043172014-01-23 14:24:41 +01002138 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" 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 +02002140 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002141" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002142 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002143" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002144 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002146
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002148 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002149 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002150 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2151 echo "(netrw) Processing your read request..."
2152 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002153
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002155 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002157" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002158 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002160 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 " ER: the tmpfile is full path: rcp sees C:\... as host C
2162 if s:netrw_has_nt_rcp == 1
2163 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2164 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2165 else
2166 " Any way needed it machine contains a '.'
2167 let uid_machine = g:netrw_machine .'.'. $USERNAME
2168 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2171 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2172 else
2173 let uid_machine = g:netrw_machine
2174 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002176 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 +00002177 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002179
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002181 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002183" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002184 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002185 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002186 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002187 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002188 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002190 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002193 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002194 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197 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 +00002198 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 endif
2201 " 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 +00002202 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002203 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002204 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002205 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002206 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002208 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002210 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2211 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002212 q!
2213 endif
2214 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002215 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002217
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002218 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002219 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2221 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002223 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002224 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002225 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002226 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002228 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002229" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002231 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002233 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002234
Bram Moolenaar97d62492012-11-15 21:28:22 +01002235 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002236 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002239 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002241 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002247 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002248
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002253 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002256 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002259
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 " perform ftp:
2261 " -i : turns off interactive prompting from ftp
2262 " -n unix : DON'T use <.netrc>, even though it exists
2263 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002264 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002265 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002266 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2267 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002269 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002270 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002271 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002273 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002274 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002276
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002278 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002282 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 else
2284 let useport= ""
2285 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002286 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2287 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002288 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002289 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2290 else
2291 let tmpfile_get = tmpfile
2292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002293 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 +00002294 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002296
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002298 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002299 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002300" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002301 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002302 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002303 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002304 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002305" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002306 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002308
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002309 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2310 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002311" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002312 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002313 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 +00002314 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002315 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 +00002316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002317 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002318
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002319 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002320 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002322 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2323 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2325" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2326 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 +00002327 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002329 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002330 endif
2331 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002332" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002333 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002334
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002336 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002337 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002339
Bram Moolenaar5c736222010-01-06 20:54:52 +01002340 if !executable(g:netrw_dav_cmd)
2341 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2342" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2343 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002344 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002346 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 +01002347 else
2348 " Construct execution string (four lines) which will be passed through filter
2349 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2350 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002351 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002353 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002354 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002355 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002357 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002358 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002359 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2361 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002362
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002364 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002366 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002367 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002368 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002369 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002370
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002371 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002373 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002374" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002375 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 +00002376 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002378
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002380 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002382 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002383" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002385 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002386 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002387 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002388" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002389 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002391 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 let netrw_option= "http"
2393 else
2394 let netrw_option= "ftp"
2395 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002396" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002397
Bram Moolenaar446cb832008-06-24 21:56:24 +00002398 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002399 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 +00002400 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002401 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 +00002402 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002403
Bram Moolenaar446cb832008-06-24 21:56:24 +00002404 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002407 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002408
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002409 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002410 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002411 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002412" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2413 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 +00002414 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002415 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002418 " NetRead: (file) NetRead Method #10 {{{3
2419 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002420" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2421 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002422 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2423 let b:netrw_lastfile = choice
2424
2425 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002426 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002427 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002428 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 endif
2430 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002431
Bram Moolenaar5c736222010-01-06 20:54:52 +01002432 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002434" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002435 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 unlet b:netrw_fname
2437 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002438 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 +01002439" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002440 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002441 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002442 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002443
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445endfun
2446
2447" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002448" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002449fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002450" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002451
Bram Moolenaar5c736222010-01-06 20:54:52 +01002452 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002453 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002454 call s:NetrwOptionsSave("w:")
2455 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002456
Bram Moolenaar5c736222010-01-06 20:54:52 +01002457 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002458 let tmpfile= s:GetTempfile("")
2459 if tmpfile == ""
2460" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002461 return
2462 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002463
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002464 if a:0 == 0
2465 let ichoice = 0
2466 else
2467 let ichoice = 1
2468 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002469
Bram Moolenaar9964e462007-05-05 17:54:07 +00002470 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002471" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002472 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002473 " For binary writes, always write entire file.
2474 " (line numbers don't really make sense for that).
2475 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002476" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002477 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002478 elseif g:netrw_cygwin
2479 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002480 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" 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 +01002482 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002483 else
2484 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" 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 +01002486 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002487 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002488
Bram Moolenaar9964e462007-05-05 17:54:07 +00002489 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002490 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002491 " on the temporary file's name. Deletion of the temporary file during
2492 " cleanup then causes an error message.
2493 0file!
2494 endif
2495
Bram Moolenaar5c736222010-01-06 20:54:52 +01002496 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002497 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002498
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002500 " attempt to repeat with previous host-file-etc
2501 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002502" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002503 let choice = b:netrw_lastfile
2504 let ichoice= ichoice + 1
2505 else
2506 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002507
Bram Moolenaar8d043172014-01-23 14:24:41 +01002508 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002510 echomsg 'NetWrite Usage:"'
2511 echomsg ':Nwrite machine:path uses rcp'
2512 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2513 echomsg ':Nwrite "machine id password path" uses ftp'
2514 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2515 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2516 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2517 echomsg ':Nwrite rcp://machine/path uses rcp'
2518 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2519 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2520 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002521 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002522 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002523
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002524 elseif match(choice,"^\"") != -1
2525 if match(choice,"\"$") != -1
2526 " case "..."
2527 let choice=strpart(choice,1,strlen(choice)-2)
2528 else
2529 " case "... ... ..."
2530 let choice = strpart(choice,1,strlen(choice)-1)
2531 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002532
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002533 while match(choice,"\"$") == -1
2534 let wholechoice= wholechoice . " " . choice
2535 let ichoice = ichoice + 1
2536 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002537 if !exists("g:netrw_quiet")
2538 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2539 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002540" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 return
2542 endif
2543 let choice= a:{ichoice}
2544 endwhile
2545 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2546 endif
2547 endif
2548 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002549 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002550" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002551
Bram Moolenaar9964e462007-05-05 17:54:07 +00002552 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002553 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002554 if !exists("b:netrw_method") || b:netrw_method < 0
2555" call Dfunc("netrw#NetWrite : unsupported method")
2556 return
2557 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002558
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002559 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002560 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002561 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002562 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2563 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002564" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002565 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002566
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002568 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002569 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002570" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 if s:netrw_has_nt_rcp == 1
2572 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2573 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2574 else
2575 let uid_machine = g:netrw_machine .'.'. $USERNAME
2576 endif
2577 else
2578 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2579 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2580 else
2581 let uid_machine = g:netrw_machine
2582 endif
2583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002584 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 +00002585 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002586
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002587 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002588 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002589 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002590" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591 let netrw_fname = b:netrw_fname
2592
2593 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2594 let bhkeep = &l:bh
2595 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002596 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002600 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002601 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002603 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002606 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002607 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610 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 +00002611 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2613 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 endif
2615 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2616 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002617 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002618 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002619 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002620 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002622
2623 " remove enew buffer (quietly)
2624 let filtbuf= bufnr("%")
2625 exe curbuf."b!"
2626 let &l:bh = bhkeep
2627 exe filtbuf."bw!"
2628
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002630
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002631 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002632 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002633 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002634 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002635" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002636 let netrw_fname = b:netrw_fname
2637 let bhkeep = &l:bh
2638
2639 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2640 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002641 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002642 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002643 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002645 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002646 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002648 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002649 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002650" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002652 if exists("g:netrw_uid") && g:netrw_uid != ""
2653 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002654 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002656 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002664 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002667 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002668 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002670 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 " save choice/id/password for future use
2674 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002675
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 " perform ftp:
2677 " -i : turns off interactive prompting from ftp
2678 " -n unix : DON'T use <.netrc>, even though it exists
2679 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002680 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002681 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2683 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002684 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002685 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002686 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002687 let mod=1
2688 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002689
2690 " remove enew buffer (quietly)
2691 let filtbuf= bufnr("%")
2692 exe curbuf."b!"
2693 let &l:bh= bhkeep
2694 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002695
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002697 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002698 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002699" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002701 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002702 else
2703 let useport= ""
2704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002705 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 +00002706 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002707
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002709 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002712 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2713 if executable(curl)
2714 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715 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 +01002716 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002717 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002718 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002719
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002720 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002721 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002722 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002723" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002724
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002725 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002726 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2727 let bhkeep = &l:bh
2728
2729 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2730 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002731 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002732 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733
Bram Moolenaarff034192013-04-24 18:51:19 +02002734 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002735 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002736 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002737 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002738 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002739 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002740 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002741 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002742 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002744
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002746 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002748
2749 " remove enew buffer (quietly)
2750 let filtbuf= bufnr("%")
2751 exe curbuf."b!"
2752 let &l:bh = bhkeep
2753 exe filtbuf."bw!"
2754
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002755 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002756
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002757 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002758 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002759 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002760" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002761 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 +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: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002766 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002767" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002768 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2770 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2771 else
2772 let uid_machine = g:netrw_machine
2773 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002774
2775 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2776 let bhkeep = &l:bh
2777 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002778 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002780
Bram Moolenaarff034192013-04-24 18:51:19 +02002781 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002783" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002784 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002785 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786 let filtbuf= bufnr("%")
2787 exe curbuf."b!"
2788 let &l:bh = bhkeep
2789 exe filtbuf."bw!"
2790 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002791
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002792 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002793 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002794 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002795 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002796 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002798 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002799
Bram Moolenaar5c736222010-01-06 20:54:52 +01002800 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002801" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002802 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002803" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002804 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002806 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002807
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002808 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002810 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" 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 +02002812 elseif !exists("leavemod")
2813 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002815 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002818
Bram Moolenaar9964e462007-05-05 17:54:07 +00002819" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002820endfun
2821
2822" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002823" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002824" uses NetRead to get a copy of the file into a temporarily file,
2825" then sources that file,
2826" then removes that file.
2827fun! netrw#NetSource(...)
2828" call Dfunc("netrw#NetSource() a:0=".a:0)
2829 if a:0 > 0 && a:1 == '?'
2830 " give help
2831 echomsg 'NetSource Usage:'
2832 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2833 echomsg ':Nsource fetch://machine/path uses fetch'
2834 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002835 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002836 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2837 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2838 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2839 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2840 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002841 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002842 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002843 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002844 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002845" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002847" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002848 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002850 if delete(s:netrw_tmpfile)
2851 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2852 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 unlet s:netrw_tmpfile
2854 else
2855 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2856 endif
2857 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002858 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002859 endif
2860" call Dret("netrw#NetSource")
2861endfun
2862
Bram Moolenaar8d043172014-01-23 14:24:41 +01002863" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002864" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2865" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002866fun! netrw#SetTreetop(iscmd,...)
2867" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2868" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002869
Bram Moolenaar85850f32019-07-19 22:05:51 +02002870 " iscmd==0: netrw#SetTreetop called using gn mapping
2871 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2872" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002873 " clear out the current tree
2874 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002875" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002876 let inittreetop= w:netrw_treetop
2877 unlet w:netrw_treetop
2878 endif
2879 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002880" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002881 unlet w:netrw_treedict
2882 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002883" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002884
Bram Moolenaar85850f32019-07-19 22:05:51 +02002885 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002886 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889 if isdirectory(s:NetrwFile(a:1))
2890" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002891 let treedir = a:1
2892 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002894 let treedir = b:netrw_curdir."/".a:1
2895 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002896" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 " normally the cursor is left in the message window.
2899 " However, here this results in the directory being listed in the message window, which is not wanted.
2900 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002901 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = "."
2904 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002905 endif
2906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002908
2909 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910 let islocal= expand("%") !~ '^\a\{3,}://'
2911" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002912
2913 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002914 if islocal
2915 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2916 else
2917 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2918 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002919
Bram Moolenaara6878372014-03-22 21:02:50 +01002920" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002921endfun
2922
Bram Moolenaar9964e462007-05-05 17:54:07 +00002923" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002924" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002925" readcmd == %r : replace buffer with newly read file
2926" == 0r : read file at top of buffer
2927" == r : read file after current line
2928" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002929fun! s:NetrwGetFile(readcmd, tfile, method)
2930" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002931
2932 " readcmd=='t': simply do nothing
2933 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002934" 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 +01002935" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002936 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002937 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002938
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939 " get name of remote filename (ie. url and all)
2940 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002941" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002942
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943 if exists("*NetReadFixup")
2944 " for the use of NetReadFixup (not otherwise used internally)
2945 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002946 endif
2947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 if a:readcmd[0] == '%'
2949 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951
2952 " rename the current buffer to the temp file (ie. tfile)
2953 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002954 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 else
2956 let tfile= a:tfile
2957 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002958 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959
2960 " edit temporary file (ie. read the temporary file in)
2961 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002962" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963 call zip#Browse(tfile)
2964 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002965" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002967 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002970 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002973 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 call tar#Browse(tfile)
2976 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002981 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 endif
2983
2984 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002985 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002986
Bram Moolenaar71badf92023-04-22 22:40:14 +01002987 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002988 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002989 " Note that isk must not include a "/" for scripts.vim
2990 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002991" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2992" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002993" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002994" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2995 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002996 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002997 filetype detect
2998" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002999 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003000" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003001 let line1 = 1
3002 let line2 = line("$")
3003
Bram Moolenaar8d043172014-01-23 14:24:41 +01003004 elseif !&ma
3005 " 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 +01003006 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003007" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003008 return
3009
Bram Moolenaar9964e462007-05-05 17:54:07 +00003010 elseif s:FileReadable(a:tfile)
3011 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003012" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 let curline = line(".")
3014 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003016 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 let line1= curline + 1
3018 let line2= line("$") - lastline + 1
3019
3020 else
3021 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003022" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3023" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003024 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003025" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 return
3027 endif
3028
3029 " User-provided (ie. optional) fix-it-up command
3030 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003031" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003032 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003033" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003035 endif
3036
Bram Moolenaaradc21822011-04-01 18:03:16 +02003037 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003038 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003039 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003040 endif
3041
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003042" 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 +00003043
3044 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003045" redraw!
3046
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003047" 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 +00003048" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003049endfun
3050
Bram Moolenaar9964e462007-05-05 17:54:07 +00003051" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003052" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003053" Input:
3054" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3055" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003056" b:netrw_method= 1: rcp
3057" 2: ftp + <.netrc>
3058" 3: ftp + machine, id, password, and [path]filename
3059" 4: scp
3060" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003061" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003062" 7: rsync
3063" 8: fetch
3064" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003065" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003066" g:netrw_machine= hostname
3067" b:netrw_fname = filename
3068" g:netrw_port = optional port number (for ftp)
3069" g:netrw_choice = copy of input url (choice)
3070fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003071" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003072
Bram Moolenaar251e1912011-06-19 05:09:16 +02003073 " sanity check: choice should have at least three slashes in it
3074 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3075 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3076 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003077" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003078 return
3079 endif
3080
Bram Moolenaar5c736222010-01-06 20:54:52 +01003081 " record current g:netrw_machine, if any
3082 " curmachine used if protocol == ftp and no .netrc
3083 if exists("g:netrw_machine")
3084 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003085" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003086 else
3087 let curmachine= "N O T A HOST"
3088 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003089 if exists("g:netrw_port")
3090 let netrw_port= g:netrw_port
3091 endif
3092
3093 " insure that netrw_ftp_cmd starts off every method determination
3094 " with the current g:netrw_ftp_cmd
3095 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003096
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003097 " initialization
3098 let b:netrw_method = 0
3099 let g:netrw_machine = ""
3100 let b:netrw_fname = ""
3101 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003102 let g:netrw_choice = a:choice
3103
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003105 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003106 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3107 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003108 " rcpurm : rcp://[user@]host/filename Use rcp
3109 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003110 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003111 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003112 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " rsyncurm : rsync://host[:port]/path Use rsync
3114 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3115 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003116 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3118 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003119 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3120 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003122 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003123 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003124 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003126 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003128 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003129
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003130" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003132 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003135 let b:netrw_method = 1
3136 let userid = substitute(a:choice,rcpurm,'\1',"")
3137 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3138 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 if userid != ""
3140 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003142
Bram Moolenaaradc21822011-04-01 18:03:16 +02003143 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003145" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003146 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003147 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3148 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3149 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003150
Bram Moolenaar15146672011-10-20 22:22:38 +02003151 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003153" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003154 let b:netrw_method = 5
3155 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3156 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003157 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003158
Bram Moolenaaradc21822011-04-01 18:03:16 +02003159 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003160 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003163 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003164 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3165 else
3166 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3167 endif
3168 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003169
Bram Moolenaaradc21822011-04-01 18:03:16 +02003170 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003172" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 let b:netrw_method = 7
3174 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3175 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003176
Bram Moolenaaradc21822011-04-01 18:03:16 +02003177 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003179" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003180 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3182 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3183 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 if userid != ""
3186 let g:netrw_uid= userid
3187 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003188
Bram Moolenaaradc21822011-04-01 18:03:16 +02003189 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003190 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003191 call NetUserPass("ftp:".g:netrw_machine)
3192 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003193 " if there's a change in hostname, require password re-entry
3194 unlet s:netrw_passwd
3195 endif
3196 if exists("netrw_port")
3197 unlet netrw_port
3198 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003199 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200
Bram Moolenaar446cb832008-06-24 21:56:24 +00003201 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003202 let b:netrw_method = 3
3203 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003204 let host= substitute(g:netrw_machine,'\..*$','','')
3205 if exists("s:netrw_hup[host]")
3206 call NetUserPass("ftp:".host)
3207
Nir Lichtman1e34b952024-05-08 19:19:34 +02003208 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003209" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3210" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003211 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003212 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003213" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003214 endif
3215 let b:netrw_method= 2
3216 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003218 let b:netrw_method= 2
3219 else
3220 if !exists("g:netrw_uid") || g:netrw_uid == ""
3221 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003222 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003223 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003224 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003225 endif
3226 let b:netrw_method= 3
3227 endif
3228 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003229
Bram Moolenaaradc21822011-04-01 18:03:16 +02003230 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003232" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 let b:netrw_method = 8
3234 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3235 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3236 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3237 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaaradc21822011-04-01 18:03:16 +02003239 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3244 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003245 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003246 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003247 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003248
Bram Moolenaaradc21822011-04-01 18:03:16 +02003249 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003251" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003252 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 let b:netrw_method = 3
3254 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3255 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003256
Bram Moolenaar9964e462007-05-05 17:54:07 +00003257 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 let b:netrw_method = 2
3259 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3260 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3261 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003262
Bram Moolenaaradc21822011-04-01 18:03:16 +02003263 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003264 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003265" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 let b:netrw_method = 9
3267 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3268 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003269
Bram Moolenaaradc21822011-04-01 18:03:16 +02003270 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003273 let b:netrw_method = 1
3274 let userid = substitute(a:choice,rcphf,'\2',"")
3275 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3276 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3278" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3279" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3280" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003281 if userid != ""
3282 let g:netrw_uid= userid
3283 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003284
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003285 " Method#10: file://user@hostname/...path-to-file {{{3
3286 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003287" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003288 let b:netrw_method = 10
3289 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003290" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003291
Bram Moolenaaradc21822011-04-01 18:03:16 +02003292 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003293 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003294 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003295 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003296 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003297 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003299 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003300
Bram Moolenaar81695252004-12-29 20:58:21 +00003301 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003302 " remove any leading [:#] from port number
3303 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3304 elseif exists("netrw_port")
3305 " retain port number as implicit for subsequent ftp operations
3306 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003307 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003308
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003309" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3310" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3311" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3312" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003313" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003314" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003315" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003316" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003317" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003318" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003320" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322
Bram Moolenaar9964e462007-05-05 17:54:07 +00003323" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003324" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003325" Usage: :call NetUserPass() -- will prompt for userid and password
3326" :call NetUserPass("uid") -- will prompt for password
3327" :call NetUserPass("uid","password") -- sets global userid and password
3328" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3329" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330fun! NetUserPass(...)
3331
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003332" call Dfunc("NetUserPass() a:0=".a:0)
3333
3334 if !exists('s:netrw_hup')
3335 let s:netrw_hup= {}
3336 endif
3337
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003339 " case: no input arguments
3340
3341 " change host and username if not previously entered; get new password
3342 if !exists("g:netrw_machine")
3343 let g:netrw_machine= input('Enter hostname: ')
3344 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003346 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 let g:netrw_uid= input('Enter username: ')
3348 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003349 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003350 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003351
3352 " set up hup database
3353 let host = substitute(g:netrw_machine,'\..*$','','')
3354 if !exists('s:netrw_hup[host]')
3355 let s:netrw_hup[host]= {}
3356 endif
3357 let s:netrw_hup[host].uid = g:netrw_uid
3358 let s:netrw_hup[host].passwd = s:netrw_passwd
3359
3360 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003361 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003362
3363 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003364 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003365 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003366" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367 let host = substitute(a:1,'^ftp:','','')
3368 let host = substitute(host,'\..*','','')
3369 if exists("s:netrw_hup[host]")
3370 let g:netrw_uid = s:netrw_hup[host].uid
3371 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003372" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3373" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374 else
3375 let g:netrw_uid = input("Enter UserId: ")
3376 let s:netrw_passwd = inputsecret("Enter Password: ")
3377 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003378
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003379 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003380 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003381" 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 +02003382 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003383 if g:netrw_machine =~ '[0-9.]\+'
3384 let host= g:netrw_machine
3385 else
3386 let host= substitute(g:netrw_machine,'\..*$','','')
3387 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003388 else
3389 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003390 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003391 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003392" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003393 if exists("g:netrw_passwd")
3394 " ask for password if one not previously entered
3395 let s:netrw_passwd= g:netrw_passwd
3396 else
3397 let s:netrw_passwd = inputsecret("Enter Password: ")
3398 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003399 endif
3400
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003401" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402 if exists("host")
3403 if !exists('s:netrw_hup[host]')
3404 let s:netrw_hup[host]= {}
3405 endif
3406 let s:netrw_hup[host].uid = g:netrw_uid
3407 let s:netrw_hup[host].passwd = s:netrw_passwd
3408 endif
3409
3410 elseif a:0 == 2
3411 let g:netrw_uid = a:1
3412 let s:netrw_passwd = a:2
3413
3414 elseif a:0 == 3
3415 " enter hostname, user-id, and password into the hup dictionary
3416 let host = substitute(a:1,'^\a\+:','','')
3417 let host = substitute(host,'\..*$','','')
3418 if !exists('s:netrw_hup[host]')
3419 let s:netrw_hup[host]= {}
3420 endif
3421 let s:netrw_hup[host].uid = a:2
3422 let s:netrw_hup[host].passwd = a:3
3423 let g:netrw_uid = s:netrw_hup[host].uid
3424 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003425" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3426" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003428
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003429" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431
Bram Moolenaar85850f32019-07-19 22:05:51 +02003432" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003433" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003434" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003436" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003437" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3438fun! s:ExplorePatHls(pattern)
3439" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3440 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003441" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003442 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003443" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003444 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3445" call Dret("s:ExplorePatHls repat<".repat.">")
3446 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003447endfun
3448
3449" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003450" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003451" 0: (user: <mb>) bookmark current directory
3452" 1: (user: <gb>) change to the bookmarked directory
3453" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003454" 3: (browsing) records current directory history
3455" 4: (user: <u>) go up (previous) directory, using history
3456" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003457" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003458fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003459" 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 +02003460 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3461" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3462 return
3463 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003464
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003465 let ykeep = @@
3466 let curbufnr = bufnr("%")
3467
Bram Moolenaar9964e462007-05-05 17:54:07 +00003468 if a:chg == 0
3469 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003470" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003471 if exists("s:netrwmarkfilelist_{curbufnr}")
3472 call s:NetrwBookmark(0)
3473 echo "bookmarked marked files"
3474 else
3475 call s:MakeBookmark(a:curdir)
3476 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003477 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003478
KSR-Yasudaf4498252023-10-06 03:34:17 +09003479 try
3480 call s:NetrwBookHistSave()
3481 catch
3482 endtry
3483
Bram Moolenaar9964e462007-05-05 17:54:07 +00003484 elseif a:chg == 1
3485 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003486" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003487 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003488" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003489 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490 else
3491 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3492 endif
3493
3494 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003495" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003496 let didwork= 0
3497 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003498" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003499 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003500" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003501 let cnt= 1
3502 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003504 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003505 let didwork = 1
3506 let cnt = cnt + 1
3507 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003508 endif
3509
3510 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003511 " Note: history is saved only when PerformListing is done;
3512 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3513 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003514 let first = 1
3515 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003516 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003517 while ( first || cnt != g:netrw_dirhistcnt )
3518" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003519 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003520" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003521 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003522 let didwork= 1
3523 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003524 let histcnt = histcnt + 1
3525 let first = 0
3526 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003527 if cnt < 0
3528 let cnt= cnt + g:netrw_dirhistmax
3529 endif
3530 endwhile
3531 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003532 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003533 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003534 if didwork
3535 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3536 endif
3537
3538 elseif a:chg == 3
3539 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003540" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003541 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 +02003542 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003543 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3544 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003545 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003547 endif
3548
3549 elseif a:chg == 4
3550 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003551" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003552 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3554 if g:netrw_dirhistcnt < 0
3555 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003556 endif
3557 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003559 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3561" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003562 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003563 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003564" call Decho("setl ma noro",'~'.expand("<slnum>"))
3565 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003566 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003567" call Decho("setl nomod",'~'.expand("<slnum>"))
3568" 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 +00003569 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3571 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003572 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003573 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003574 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003575 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003577 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003578 echo "Sorry, no predecessor directory exists yet"
3579 endif
3580
3581 elseif a:chg == 5
3582 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003583" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3586 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3587" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003588 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003589" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003590 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003591 sil! NetrwKeepj %d _
3592" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3593" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003594 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595" 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 +02003596 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3598 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003599 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003600 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3601 if g:netrw_dirhistcnt < 0
3602 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003603 endif
3604 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003605 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003606 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003609 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003610
3611 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003612" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003613 if exists("s:netrwmarkfilelist_{curbufnr}")
3614 call s:NetrwBookmark(1)
3615 echo "removed marked files from bookmarks"
3616 else
3617 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003618 let iremove = v:count
3619 let dremove = g:netrw_bookmarklist[iremove - 1]
3620" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003621 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3623 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3624 echo "removed ".dremove." from g:netrw_bookmarklist"
3625" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003626 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003628
3629 try
3630 call s:NetrwBookHistSave()
3631 catch
3632 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003633 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003634 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003635 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003636 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003637" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003638endfun
3639
3640" ---------------------------------------------------------------------
3641" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003642" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003643" Sister function: s:NetrwBookHistSave()
3644fun! s:NetrwBookHistRead()
3645" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003646 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003647" 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 +02003648 return
3649 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003650 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003651
3652 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003653 if !exists("s:netrw_initbookhist")
3654 let home = s:NetrwHome()
3655 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003656 if filereadable(s:NetrwFile(savefile))
3657" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003658 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003659 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003660
3661 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003662 if g:netrw_dirhistmax > 0
3663 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003664 if filereadable(s:NetrwFile(savefile))
3665" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003666 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003667 endif
3668 let s:netrw_initbookhist= 1
3669 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003670 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003672
Bram Moolenaar97d62492012-11-15 21:28:22 +01003673 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003674" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3675" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676" call Dret("s:NetrwBookHistRead")
3677endfun
3678
3679" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003680" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003681" Sister function: s:NetrwBookHistRead()
3682" I used to do this via viminfo but that appears to
3683" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003684" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3685" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003687fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003688" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003689 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003691 return
3692 endif
3693
Bram Moolenaar5c736222010-01-06 20:54:52 +01003694 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003696 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003697
3698 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003701 if g:netrw_use_noswf
3702 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3703 else
3704 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3705 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003706 setl nocin noai noci magic nospell nohid wig= noaw
3707 setl ma noro write
3708 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003709 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003710
Bram Moolenaar85850f32019-07-19 22:05:51 +02003711 " rename enew'd file: .netrwhist -- no attempt to merge
3712 " record dirhistmax and current dirhistcnt
3713 " save history
3714" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003715 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003717 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3718 if g:netrw_dirhistmax > 0
3719 let lastline = line("$")
3720 let cnt = g:netrw_dirhistcnt
3721 let first = 1
3722 while ( first || cnt != g:netrw_dirhistcnt )
3723 let lastline= lastline + 1
3724 if exists("g:netrw_dirhist_{cnt}")
3725 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3726" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3727 endif
3728 let first = 0
3729 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3730 if cnt < 0
3731 let cnt= cnt + g:netrw_dirhistmax
3732 endif
3733 endwhile
3734 exe "sil! w! ".savefile
3735" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3736 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003737
Bram Moolenaar85850f32019-07-19 22:05:51 +02003738 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003739 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003741" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742 " merge and write .netrwbook
3743 let savefile= s:NetrwHome()."/.netrwbook"
3744
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003745 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003747 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003748 for bdm in booklist
3749 if index(g:netrw_bookmarklist,bdm) == -1
3750 call add(g:netrw_bookmarklist,bdm)
3751 endif
3752 endfor
3753 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 endif
3755
3756 " construct and save .netrwbook
3757 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003758 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003759" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003761
3762 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003763 let bgone= bufnr("%")
3764 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003765 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766
3767" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003768endfun
3769
3770" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003771" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3772" list of the contents of a local or remote directory. It is assumed that the
3773" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3774" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003775" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776fun! s:NetrwBrowse(islocal,dirname)
3777 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003778" 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 +02003779" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3780" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3781" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003782
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003783 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3784 " This is useful when one edits a local file, then :e ., then :Rex
3785 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3786 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003787" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003788 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003789
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003790 " s:NetrwBrowse : initialize history {{{3
3791 if !exists("s:netrw_initbookhist")
3792 NetrwKeepj call s:NetrwBookHistRead()
3793 endif
3794
3795 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003796 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003797 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003798" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003799 else
3800 let dirname= a:dirname
3801 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003802
Bram Moolenaar85850f32019-07-19 22:05:51 +02003803 " repoint t:netrw_lexbufnr if appropriate
3804 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3805" call Decho("set repointlexbufnr to true!")
3806 let repointlexbufnr= 1
3807 endif
3808
3809 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810 if exists("s:netrw_skipbrowse")
3811 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003812" 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 +01003813" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814 return
3815 endif
3816 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003817 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818" call Dret("s:NetrwBrowse : missing shellescape()")
3819 return
3820 endif
3821 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823" call Dret("s:NetrwBrowse : missing fnameescape()")
3824 return
3825 endif
3826
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003828 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003830 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003831 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3832 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3833" call Decho("clearing marked files",'~'.expand("<slnum>"))
3834 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3835 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003836 endif
3837
3838 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003840" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3841" 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 +02003842 if s:NetrwLcd(dirname)
3843" call Dret("s:NetrwBrowse : lcd failure")
3844 return
3845 endif
3846 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003847" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848
Bram Moolenaar5c736222010-01-06 20:54:52 +01003849 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003850 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003851" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003852 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003854 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003855 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858
3859 " remove any filetype indicator from end of dirname, except for the
3860 " "this is a directory" indicator (/).
3861 " There shouldn't be one of those here, anyway.
3862 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 call s:RemotePathAnalysis(dirname)
3865
3866 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3867 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003868 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 let b:netrw_curdir = dirname
3872 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3875 sil call netrw#NetRead(2,url)
3876 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003877" call Decho("url<".url.">",'~'.expand("<slnum>"))
3878" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3879" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003880 if s:path =~ '.bz2'
3881 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3882 elseif s:path =~ '.gz'
3883 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3884 elseif s:path =~ '.gz'
3885 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3886 else
3887 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889 endif
3890
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003891 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003892 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003893 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003894" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003896" 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 +00003897
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898" call Dret("s:NetrwBrowse : file<".s:fname.">")
3899 return
3900 endif
3901
Bram Moolenaaradc21822011-04-01 18:03:16 +02003902 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003903 call s:UseBufWinVars()
3904
3905 " set up some variables {{{3
3906 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003907 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003908 let s:last_sort_by = g:netrw_sort_by
3909
3910 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003911 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912
Bram Moolenaar97d62492012-11-15 21:28:22 +01003913 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003914" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003915 let svpos = winsaveview()
3916" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003917 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918
Bram Moolenaar446cb832008-06-24 21:56:24 +00003919 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003920 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3921 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3922" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3923" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3924 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3925 else
3926" " call Decho("2match none",'~'.expand("<slnum>"))
3927 2match none
3928 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003930 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003931 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003932" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003933 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003934" 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 +01003935" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003936 return
3937 endif
3938
3939 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003941 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942 if b:netrw_curdir =~ '[/\\]$'
3943 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3944 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003945 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003946 let b:netrw_curdir= b:netrw_curdir."/"
3947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 if b:netrw_curdir == ''
3949 if has("amiga")
3950 " On the Amiga, the empty string connotes the current directory
3951 let b:netrw_curdir= getcwd()
3952 else
3953 " under unix, when the root directory is encountered, the result
3954 " from the preceding substitute is an empty string.
3955 let b:netrw_curdir= '/'
3956 endif
3957 endif
3958 if !a:islocal && b:netrw_curdir !~ '/$'
3959 let b:netrw_curdir= b:netrw_curdir.'/'
3960 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003961" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003962
3963 " ------------
3964 " (local only) {{{3
3965 " ------------
3966 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003967" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003968
3969 " Set up ShellCmdPost handling. Append current buffer to browselist
3970 call s:LocalFastBrowser()
3971
3972 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3973 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3975" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003976 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003977 if s:NetrwLcd(b:netrw_curdir)
3978" call Dret("s:NetrwBrowse : lcd failure")
3979 return
3980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 endif
3982 endif
3983
3984 " --------------------------------
3985 " remote handling: {{{3
3986 " --------------------------------
3987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003988" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989
Bram Moolenaar97d62492012-11-15 21:28:22 +01003990 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" 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 +02003992 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003994" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003995 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3996 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3997 if dirname !~ '/$'
3998 let dirname= dirname.'/'
3999 endif
4000 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004003 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 endif
4006
4007 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4008 if dirname !~ dirpat
4009 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004010 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004012 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004014 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004015" 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 +00004016" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4017 return
4018 endif
4019 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004020" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004021 endif " (additional remote handling)
4022
Bram Moolenaar85850f32019-07-19 22:05:51 +02004023 " -------------------------------
4024 " Perform Directory Listing: {{{3
4025 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004026 NetrwKeepj call s:NetrwMaps(a:islocal)
4027 NetrwKeepj call s:NetrwCommands(a:islocal)
4028 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004029
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004030 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004031 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004032" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4033
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004034 " If there is a rexposn: restore position with rexposn
4035 " Otherwise : set rexposn
4036 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004037" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4038 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4039 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4040 NetrwKeepj exe w:netrw_bannercnt
4041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042 else
4043 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4044 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004045 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004046 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004047" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004048 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004049 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004050
Bram Moolenaar85850f32019-07-19 22:05:51 +02004051 " repoint t:netrw_lexbufnr if appropriate
4052 if exists("repointlexbufnr")
4053 let t:netrw_lexbufnr= bufnr("%")
4054" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4055 endif
4056
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004057 " restore position
4058 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004059" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4060 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004061 endif
4062
Bram Moolenaara6878372014-03-22 21:02:50 +01004063 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004064 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4065 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004066" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4067" 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 +02004068" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004069 return
4070endfun
4071
4072" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4074" may not apply correctly; ie. netrw's idea of the current directory may
4075" differ from vim's. This function insures that netrw's idea of the current
4076" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004077" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4080" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4081" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4082" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4083" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004084
4085 " clean up any leading treedepthstring
4086 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4087 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004088" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004089 else
4090 let fname= a:fname
4091 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004092
4093 if g:netrw_keepdir
4094 " vim's idea of the current directory possibly may differ from netrw's
4095 if !exists("b:netrw_curdir")
4096 let b:netrw_curdir= getcwd()
4097 endif
4098
Nir Lichtman1e34b952024-05-08 19:19:34 +02004099 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004100 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004102 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004103" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104 else
4105 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004107" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108 endif
4109
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004110 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004113" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 else
4115 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004117" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118 endif
4119 else
4120 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004121 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004122" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4123" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4124" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125 endif
4126
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 return ret
4129endfun
4130
4131" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004132" s:NetrwFileInfo: supports qf (query for file information) {{{2
4133fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004134" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004135 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004137 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004138 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004139 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004140 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004141 let lsopt= "-lsadh --si"
4142 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004143" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004145
4146 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004149
Bram Moolenaara6878372014-03-22 21:02:50 +01004150 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004153
4154 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004155 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
Bram Moolenaar446cb832008-06-24 21:56:24 +00004158 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004162 endif
4163 else
4164 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4166 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 let fname= substitute(a:fname,".$","","")
4168 else
4169 let fname= a:fname
4170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171 let t = getftime(s:NetrwFile(fname))
4172 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004173 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004174 let sz= s:NetrwHumanReadable(sz)
4175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4177" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004178 endif
4179 else
4180 echo "sorry, \"qf\" not supported yet for remote files"
4181 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004182 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004183" call Dret("s:NetrwFileInfo")
4184endfun
4185
4186" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004187" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4188fun! s:NetrwFullPath(filename)
4189" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4190 let filename= a:filename
4191 if filename !~ '^/'
4192 let filename= resolve(getcwd().'/'.filename)
4193 endif
4194 if filename != "/" && filename =~ '/$'
4195 let filename= substitute(filename,'/$','','')
4196 endif
4197" " call Dret("s:NetrwFullPath <".filename.">")
4198 return filename
4199endfun
4200
4201" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004202" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004203" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004204" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004205" 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 +00004206fun! s:NetrwGetBuffer(islocal,dirname)
4207" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004208" 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 +02004209" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4210" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211 let dirname= a:dirname
4212
4213 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004214" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004215 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004216" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004217 let s:netrwbuf= {}
4218 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004219" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4220" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4221
4222 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4223 let bufnum = -1
4224
4225 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4226 if has_key(s:netrwbuf,"NetrwTreeListing")
4227 let bufnum= s:netrwbuf["NetrwTreeListing"]
4228 else
4229 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4230 endif
4231" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4232 if !bufexists(bufnum)
4233 call remove(s:netrwbuf,"NetrwTreeListing"])
4234 let bufnum= -1
4235 endif
4236 elseif bufnr("NetrwTreeListing") != -1
4237 let bufnum= bufnr("NetrwTreeListing")
4238" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4239 else
4240" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4241 let bufnum= -1
4242 endif
4243
4244 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004245 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004246" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004247 if !bufexists(bufnum)
4248 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4249 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004251
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004253" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004254 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4257
Bram Moolenaar71badf92023-04-22 22:40:14 +01004258 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004259 " IF the buffer already has the desired name
4260 " AND it is empty
4261 let curbuf = bufname("%")
4262 if curbuf == '.'
4263 let curbuf = getcwd()
4264 endif
4265" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004266" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004267" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4268" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4269" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4270" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4271 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004272" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4273 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004274 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004275" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004276 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004277 " 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 +00004278
4279 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004280 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004281" 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 +00004282 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004283" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004284 " name the buffer
4285 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4286 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004288 let w:netrw_treebufnr = bufnr("%")
4289 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004290 if g:netrw_use_noswf
4291 setl nobl bt=nofile noswf
4292 else
4293 setl nobl bt=nofile
4294 endif
4295 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4296 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4297 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4298 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004299" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004301 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004302 " enter the new buffer into the s:netrwbuf dictionary
4303 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4304" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4305" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004307" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308
4309 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004311 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004313 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004314
4315 if &ft == "netrw"
4316" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4317 exe "sil! NetrwKeepj noswapfile b ".bufnum
4318" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004320" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4321 call s:NetrwEditBuf(bufnum)
4322" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004324" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004326 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004328
4329 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004331
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004332 if line("$") <= 1 && getline(1) == ""
4333 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004334 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004335" 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>"))
4336" 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 +01004337" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4338 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004339
Bram Moolenaar97d62492012-11-15 21:28:22 +01004340 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004342 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004343 sil NetrwKeepj %d _
4344" 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>"))
4345" 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 +01004346" 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 +00004347 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004348
Bram Moolenaar446cb832008-06-24 21:56:24 +00004349 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4351" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004352 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004353 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004354 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" 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>"))
4356" 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 +01004357" 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 +00004358 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004359
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004361" 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>"))
4362" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4363" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 return 1
4365 endif
4366 endif
4367
4368 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4369 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4370 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4371 " med 1 D H
4372 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004373" 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 +00004374 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004375 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004376 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377
4378 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004379" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4380" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4381 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004382
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" 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>"))
4384" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4385" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386 return 0
4387endfun
4388
4389" ---------------------------------------------------------------------
4390" s:NetrwGetcwd: get the current directory. {{{2
4391" Change backslashes to forward slashes, if any.
4392" If doesc is true, escape certain troublesome characters
4393fun! s:NetrwGetcwd(doesc)
4394" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4395 let curdir= substitute(getcwd(),'\\','/','ge')
4396 if curdir !~ '[\/]$'
4397 let curdir= curdir.'/'
4398 endif
4399 if a:doesc
4400 let curdir= fnameescape(curdir)
4401 endif
4402" call Dret("NetrwGetcwd <".curdir.">")
4403 return curdir
4404endfun
4405
4406" ---------------------------------------------------------------------
4407" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4408fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004409" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4410" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4411 let keepsol= &l:sol
4412 setl nosol
4413
Bram Moolenaar446cb832008-06-24 21:56:24 +00004414 call s:UseBufWinVars()
4415
4416 " insure that w:netrw_liststyle is set up
4417 if !exists("w:netrw_liststyle")
4418 if exists("g:netrw_liststyle")
4419 let w:netrw_liststyle= g:netrw_liststyle
4420 else
4421 let w:netrw_liststyle= s:THINLIST
4422 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004423" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424 endif
4425
4426 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4427 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004428" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004429 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 let dirname= "./"
4431 let curline= getline('.')
4432
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004433 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004434 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 let s:netrw_skipbrowse= 1
4436 echo 'Pressing "s" also works'
4437
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004438 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004439 let s:netrw_skipbrowse= 1
4440 echo 'Press "S" to edit sorting sequence'
4441
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004442 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004443 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004446 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004447 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004448 let s:netrw_skipbrowse= 1
4449 echo 'Pressing "a" also works'
4450
4451 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004452 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453 endif
4454
4455 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004456" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004457 NetrwKeepj norm! 0
4458 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459
4460 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004461" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004462 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4464
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004465 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004466" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004467 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469
4470 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004471" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472 let dirname= getline('.')
4473
4474 if !exists("b:netrw_cpf")
4475 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004476 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 +01004477 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004478" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004479 endif
4480
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004481" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004482 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4484" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004486 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 else
4488 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004489 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 endif
Enno3146d632024-07-04 19:44:42 +02004491
4492 let dict={}
4493 " save the unnamed register and register 0-9 and a
4494 let dict.a=[getreg('a'), getregtype('a')]
4495 for i in range(0, 9)
4496 let dict[i] = [getreg(i), getregtype(i)]
4497 endfor
4498 let dict.unnamed = [getreg(''), getregtype('')]
4499
Bram Moolenaarc236c162008-07-13 17:41:49 +00004500 let eofname= filestart + b:netrw_cpf + 1
4501 if eofname <= col("$")
4502 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004503 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004504 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004505 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004506 endif
Enno3146d632024-07-04 19:44:42 +02004507
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004509 call s:RestoreRegister(dict)
4510
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004511" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004512 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004514 endif
4515
4516 " symlinks are indicated by a trailing "@". Remove it before further processing.
4517 let dirname= substitute(dirname,"@$","","")
4518
4519 " executables are indicated by a trailing "*". Remove it before further processing.
4520 let dirname= substitute(dirname,"\*$","","")
4521
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522 let &l:sol= keepsol
4523
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524" call Dret("s:NetrwGetWord <".dirname.">")
4525 return dirname
4526endfun
4527
4528" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004529" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4530" g:netrw_bufsettings will be used after the listing is produced.
4531" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532fun! s:NetrwListSettings(islocal)
4533" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004534" 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 +00004535 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004536" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4537 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4538 setl bt=nofile nobl ma nonu nowrap noro nornu
4539 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004540 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004541 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004543" call Dredir("ls!","s:NetrwListSettings")
4544" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004545 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004548 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004550 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004552" 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 +00004553" call Dret("s:NetrwListSettings")
4554endfun
4555
4556" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004557" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004558" islocal=0: remote browsing
4559" =1: local browsing
4560fun! s:NetrwListStyle(islocal)
4561" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004562
Bram Moolenaar97d62492012-11-15 21:28:22 +01004563 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564 let fname = s:NetrwGetWord()
4565 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004566 let svpos = winsaveview()
4567" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004569" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4570" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4571" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572
Bram Moolenaar85850f32019-07-19 22:05:51 +02004573 " repoint t:netrw_lexbufnr if appropriate
4574 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4575" call Decho("set repointlexbufnr to true!")
4576 let repointlexbufnr= 1
4577 endif
4578
Bram Moolenaar446cb832008-06-24 21:56:24 +00004579 if w:netrw_liststyle == s:THINLIST
4580 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004581" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4583
4584 elseif w:netrw_liststyle == s:LONGLIST
4585 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004586" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004587 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4588
4589 elseif w:netrw_liststyle == s:WIDELIST
4590 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4593
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004594 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004595" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4597
4598 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004599 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004600 let g:netrw_liststyle = s:THINLIST
4601 let w:netrw_liststyle = g:netrw_liststyle
4602 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4603 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004604 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004605" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004606
4607 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004608" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4609 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004610 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004611" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004612 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" 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 +00004614
4615 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004616" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004617 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004618 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004619
Bram Moolenaar85850f32019-07-19 22:05:51 +02004620 " repoint t:netrw_lexbufnr if appropriate
4621 if exists("repointlexbufnr")
4622 let t:netrw_lexbufnr= bufnr("%")
4623" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4624 endif
4625
Bram Moolenaar13600302014-05-22 18:26:40 +02004626 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004627" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4628 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004629 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004630
4631" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4632endfun
4633
4634" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004635" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4636fun! s:NetrwBannerCtrl(islocal)
4637" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4638
Bram Moolenaar97d62492012-11-15 21:28:22 +01004639 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004640 " toggle the banner (enable/suppress)
4641 let g:netrw_banner= !g:netrw_banner
4642
4643 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004644 let svpos= winsaveview()
4645" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004646 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4647
4648 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004649 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4650 let fname= s:NetrwGetWord()
4651 sil NetrwKeepj $
4652 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4653" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4654 if result <= 0 && exists("w:netrw_bannercnt")
4655 exe "NetrwKeepj ".w:netrw_bannercnt
4656 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004658 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004659" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4660endfun
4661
4662" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004663" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4664"
4665" No bang: enters files/directories into Netrw's bookmark system
4666" No argument and in netrw buffer:
4667" if there are marked files: bookmark marked files
4668" otherwise : bookmark file/directory under cursor
4669" No argument and not in netrw buffer: bookmarks current open file
4670" Has arguments: globs them individually and bookmarks them
4671"
4672" With bang: deletes files/directories from Netrw's bookmark system
4673fun! s:NetrwBookmark(del,...)
4674" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4675 if a:0 == 0
4676 if &ft == "netrw"
4677 let curbufnr = bufnr("%")
4678
4679 if exists("s:netrwmarkfilelist_{curbufnr}")
4680 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004681" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004682 let svpos = winsaveview()
4683" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004684 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004685 for fname in s:netrwmarkfilelist_{curbufnr}
4686 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4687 endfor
4688 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4689 call s:NetrwUnmarkList(curbufnr,curdir)
4690 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004691" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4692 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004693 else
4694 let fname= s:NetrwGetWord()
4695 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4696 endif
4697
4698 else
4699 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004700" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004701 let fname= expand("%")
4702 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4703 endif
4704
4705 else
4706 " bookmark specified files
4707 " attempts to infer if working remote or local
4708 " by deciding if the current file begins with an url
4709 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004710 let islocal= expand("%") !~ '^\a\{3,}://'
4711" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004712 let i = 1
4713 while i <= a:0
4714 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004715 if v:version > 704 || (v:version == 704 && has("patch656"))
4716 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004717 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004718 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004720 else
4721 let mbfiles= [a:{i}]
4722 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004723" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004724 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004725" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004726 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4727 endfor
4728 let i= i + 1
4729 endwhile
4730 endif
4731
4732 " update the menu
4733 call s:NetrwBookmarkMenu()
4734
4735" call Dret("s:NetrwBookmark")
4736endfun
4737
4738" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004739" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4740" .2.[cnt] for bookmarks, and
4741" .3.[cnt] for history
4742" (see s:NetrwMenu())
4743fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004744 if !exists("s:netrw_menucnt")
4745 return
4746 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004747" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004748
4749 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004750 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004751 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004752" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004753 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4754 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004755 endif
4756 if !exists("s:netrw_initbookhist")
4757 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004758 endif
4759
4760 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004761 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004762 let cnt= 1
4763 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004764" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004765 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004766
4767 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004768 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004769
4770 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004771 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 +01004772 let cnt= cnt + 1
4773 endfor
4774
4775 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776
4777 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004778 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004779 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004780 let first = 1
4781 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004782 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004783 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004784 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 if exists("g:netrw_dirhist_{cnt}")
4786 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004787" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4789 endif
4790 let first = 0
4791 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4792 if cnt < 0
4793 let cnt= cnt + g:netrw_dirhistmax
4794 endif
4795 endwhile
4796 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004797
Bram Moolenaar9964e462007-05-05 17:54:07 +00004798 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004799" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004800endfun
4801
4802" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004803" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4804" directory and a new directory name. Also, if the
4805" "new directory name" is actually a file,
4806" NetrwBrowseChgDir() edits the file.
4807fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004808" 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 +01004809" 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 +00004810
Bram Moolenaar97d62492012-11-15 21:28:22 +01004811 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812 if !exists("b:netrw_curdir")
4813 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4814 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004815 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004816" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4817" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004818" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004820 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004821 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004822" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004823
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004824 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004825" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004826 call s:SavePosn(s:netrw_posn)
4827 NetrwKeepj call s:NetrwOptionsSave("s:")
4828 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004829 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004830 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004831 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004832 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004833 endif
4834 let newdir = a:newdir
4835 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004836 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004837" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004838" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004839" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004840
4841 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004842" 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 +01004843 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004844" 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 +01004845 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004846 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004847" 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 +01004848 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004849" 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 +02004850 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004851 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004852 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004853 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004854" 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 +01004855 endif
4856 endif
4857" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004858" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004859 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004860
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861 " set up o/s-dependent directory recognition pattern
4862 if has("amiga")
4863 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004864 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 let dirpat= '[\/]$'
4866 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868
4869 if dirname !~ dirpat
4870 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004871 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004872 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004873" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 endif
4875
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004876" 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 +01004877 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004878 " ------------------------------
4879 " NetrwBrowseChgDir: edit a file {{{3
4880 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004881" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004882
Bram Moolenaar97d62492012-11-15 21:28:22 +01004883 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004884 let s:rexposn_{bufnr("%")}= winsaveview()
4885" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004886" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4887" 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 +01004888
Bram Moolenaar446cb832008-06-24 21:56:24 +00004889 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004890" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4891" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004892" let newdir = s:NetrwTreePath(s:netrw_treetop)
4893" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004894 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004895 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4896" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4897 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 if dirname =~ '/$'
4899 let dirname= dirname.newdir
4900 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004901 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004903" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4904" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004906" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004908 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004911" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004912 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004914" 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 +02004915 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004916 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004917 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004918" " 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 +01004919 if type(g:netrw_browse_split) == 3
4920 " open file in server
4921 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004923 call s:NetrwServerEdit(a:islocal,dirname)
4924" call Dret("s:NetrwBrowseChgDir")
4925 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004926
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004927 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004928 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004929" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004930 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4931 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004932 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004933 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004934 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004935 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004936
Bram Moolenaar446cb832008-06-24 21:56:24 +00004937 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004938 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004939" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004940 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4941 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004942 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004943 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004944 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004945 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004946
Bram Moolenaar446cb832008-06-24 21:56:24 +00004947 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004948 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004949" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004950 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004951 if !exists("b:netrw_curdir")
4952 let b:netrw_curdir= getcwd()
4953 endif
4954 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004955
Bram Moolenaar446cb832008-06-24 21:56:24 +00004956 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004957 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004958" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004959 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004960 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004962 return
4963 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004964 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004965
Bram Moolenaar9964e462007-05-05 17:54:07 +00004966 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004967 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004968" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004969 call s:NetrwMenu(0)
4970 " optional change to window
4971 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004972" 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 +02004973 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004974 " if g:netrw_chgwin is set to one more than the last window, then
4975 " vertically split the last window to make that window available.
4976 let curwin= winnr()
4977 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4978 vs
4979 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004980 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004981 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004982 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004983 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004984 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004985
Bram Moolenaar9964e462007-05-05 17:54:07 +00004986 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004987
Bram Moolenaar446cb832008-06-24 21:56:24 +00004988 " the point where netrw actually edits the (local) file
4989 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004990 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004991 if !&mod
4992 " if e the new file would fail due to &mod, then don't change any of the flags
4993 let dolockout= 1
4994 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004995 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004996" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004997 " some like c-^ to return to the last edited file
4998 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004999 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5000 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005001 call s:NetrwEditFile("e","",dirname)
5002" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005003 " COMBAK -- cuc cul related
5004 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005005 if &hidden || &bufhidden == "hide"
5006 " file came from vim's hidden storage. Don't "restore" options with it.
5007 let dorestore= 0
5008 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005009 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005010" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005011 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005012
5013 " handle g:Netrw_funcref -- call external-to-netrw functions
5014 " This code will handle g:Netrw_funcref as an individual function reference
5015 " or as a list of function references. It will ignore anything that's not
5016 " a function reference. See :help Funcref for information about function references.
5017 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005018" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005019 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005021 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005022 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005023" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005025 if type(Fncref) == 2
5026 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005027 endif
5028 endfor
5029 endif
5030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005031 endif
5032
5033 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005034 " ----------------------------------------------------
5035 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5036 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005037" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005038 let dirname = newdir
5039 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005040 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005041 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042
5043 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005044 " ---------------------------------------------
5045 " NetrwBrowseChgDir: refresh the directory list {{{3
5046 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005047" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005048 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005049 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005050
5051 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005052 " --------------------------------------
5053 " NetrwBrowseChgDir: go up one directory {{{3
5054 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005055" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056
5057 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5058 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005059" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5060" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005061 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005062 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005063 endif
5064
5065 if has("amiga")
5066 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 if a:islocal
5069 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5070 let dirname= substitute(dirname,'/$','','')
5071 else
5072 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005074" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005075
Nir Lichtman1e34b952024-05-08 19:19:34 +02005076 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005077 " windows
5078 if a:islocal
5079 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5080 if dirname == ""
5081 let dirname= '/'
5082 endif
5083 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005084 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005085 endif
5086 if dirname =~ '^\a:$'
5087 let dirname= dirname.'/'
5088 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005090
Bram Moolenaar446cb832008-06-24 21:56:24 +00005091 else
5092 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005093" 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 +00005094 if a:islocal
5095 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5096 if dirname == ""
5097 let dirname= '/'
5098 endif
5099 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005100 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005102" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005104 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005105 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106
5107 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005108 " --------------------------------------
5109 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5110 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005111" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5113" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005114 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5117 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005118 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005119 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005120" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005121 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005122 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005123" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124
5125 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005126" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005128" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 let haskey= 1
5130 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005131" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 endif
5133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005135" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 if has_key(w:netrw_treedict,treedir."/")
5138 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005139" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005140 let haskey = 1
5141 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005142" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005143 endif
5144 endif
5145
5146 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005147" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 if !haskey && treedir =~ '/$'
5149 let treedir= substitute(treedir,'/$','','')
5150 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 let haskey = 1
5153 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005154" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 endif
5156 endif
5157
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 if haskey
5160 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005161" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5164" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005165 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005166 else
5167 " go down one directory
5168 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005169" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5170" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005172 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005173" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005174 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175
5176 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005177 " ----------------------------------------
5178 " NetrwBrowseChgDir: Go down one directory {{{3
5179 " ----------------------------------------
5180 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005181" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005182 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005183 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005184 endif
5185
Bram Moolenaar97d62492012-11-15 21:28:22 +01005186 " --------------------------------------
5187 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5188 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005189 if dorestore
5190 " dorestore is zero'd when a local file was hidden or bufhidden;
5191 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005193 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005194" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005195" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005196 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005197 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005199 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5201" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005202 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" 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 +02005204 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5206" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005207 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005209 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005210 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005211 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005212 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005213
Bram Moolenaar446cb832008-06-24 21:56:24 +00005214" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5215 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005216endfun
5217
5218" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005219" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5220" for thin, long, and wide: cursor placed just after banner
5221" for tree, keeps cursor on current filename
5222fun! s:NetrwBrowseUpDir(islocal)
5223" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005224 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5225 " this test needed because occasionally this function seems to be incorrectly called
5226 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005228 " directories.
5229" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5230 return
5231 endif
5232
Bram Moolenaara6878372014-03-22 21:02:50 +01005233 norm! 0
5234 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005235" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005236 let curline= getline(".")
5237 let swwline= winline() - 1
5238 if exists("w:netrw_treetop")
5239 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005240 elseif exists("b:netrw_curdir")
5241 let w:netrw_treetop= b:netrw_curdir
5242 else
5243 let w:netrw_treetop= getcwd()
5244 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005246 let curfile = getline(".")
5247 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005248 if a:islocal
5249 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5250 else
5251 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5252 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005253" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5254" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5255 if w:netrw_treetop == '/'
5256 keepj call search('^\M'.curfile,"w")
5257 elseif curfile == '../'
5258 keepj call search('^\M'.curfile,"wb")
5259 else
5260" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5261 while 1
5262 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5263 let treepath= s:NetrwTreePath(w:netrw_treetop)
5264" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5265 if treepath == curpath
5266 break
5267 endif
5268 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005269 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005270
Bram Moolenaara6878372014-03-22 21:02:50 +01005271 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005272" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005273 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005274 if exists("b:netrw_curdir")
5275 let curdir= b:netrw_curdir
5276 else
5277 let curdir= expand(getcwd())
5278 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005279 if a:islocal
5280 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5281 else
5282 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5283 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005284 call s:RestorePosn(s:netrw_posn)
5285 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005286 let curdir= '\<'. escape(curdir, '~'). '/'
5287 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005288 endif
5289" call Dret("s:NetrwBrowseUpDir")
5290endfun
5291
5292" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005293" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005294" given filename; typically this means given their extension.
5295" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005296fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005297 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005298" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005299
Bram Moolenaar91359012019-11-30 17:57:03 +01005300 if a:remote == 0 && isdirectory(a:fname)
5301 " if its really just a local directory, then do a "gf" instead
5302" 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 +01005303" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5304 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005305" call Dret("netrw#BrowseX")
5306 return
5307 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5308 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5309" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5310" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5311" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5312" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5313 norm! gf
5314" call Dret("netrw#BrowseX")
5315 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005316 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005317" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005319 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5320 let remote = a:remote
5321 else
5322 let remote = 0
5323 endif
5324
Bram Moolenaar97d62492012-11-15 21:28:22 +01005325 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005326 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005327" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005328
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005329 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5330 let awkeep = &aw
5331 set noaw
5332
Bram Moolenaar5c736222010-01-06 20:54:52 +01005333 " special core dump handler
5334 if a:fname =~ '/core\(\.\d\+\)\=$'
5335 if exists("g:Netrw_corehandler")
5336 if type(g:Netrw_corehandler) == 2
5337 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005338" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005339 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005340 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005341 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005342" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005344 if type(Fncref) == 2
5345 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005346 endif
5347 endfor
5348 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005349" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005350 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005351 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005352 let &aw= awkeep
5353" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005354 return
5355 endif
5356 endif
5357
Bram Moolenaar446cb832008-06-24 21:56:24 +00005358 " set up the filename
5359 " (lower case the extension, make a local copy of a remote file)
5360 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005361 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005362 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005363 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005364 if exten =~ "[\\/]"
5365 let exten= ""
5366 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005367" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005368
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005369 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005370 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005371" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005372 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005373 call netrw#NetRead(3,a:fname)
5374 " attempt to rename tempfile
5375 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005376 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005377" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5378" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005379 if s:netrw_tmpfile != newname && newname != ""
5380 if rename(s:netrw_tmpfile,newname) == 0
5381 " renaming succeeded
5382" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5383 let fname= newname
5384 else
5385 " renaming failed
5386" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5387 let fname= s:netrw_tmpfile
5388 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005390 let fname= s:netrw_tmpfile
5391 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005392 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005393" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005394 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005395 " special ~ handler for local
5396 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005397" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5398 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005399 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005400 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005401" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5402" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005403
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005404 " set up redirection (avoids browser messages)
5405 " by default, g:netrw_suppress_gx_mesg is true
5406 if g:netrw_suppress_gx_mesg
5407 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005408 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005409 let redir= substitute(&srr,"%s","nul","")
5410 else
5411 let redir= substitute(&srr,"%s","/dev/null","")
5412 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005413 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005414 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005415 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005416 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005418 else
5419 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005421" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005423 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005425" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426 if g:netrw_browsex_viewer =~ '\s'
5427 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5428 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5429 let oviewer = ''
5430 let cnt = 1
5431 while !executable(viewer) && viewer != oviewer
5432 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5433 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5434 let cnt = cnt + 1
5435 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005436" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005437 endwhile
5438 else
5439 let viewer = g:netrw_browsex_viewer
5440 let viewopt = ""
5441 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005442" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 endif
5444
5445 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005446" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005448" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 let ret= netrwFileHandlers#Invoke(exten,fname)
5450
5451 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005452" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005453 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454 let ret= v:shell_error
5455
Nir Lichtman1e34b952024-05-08 19:19:34 +02005456 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005457" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005458 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005459 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005460 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005461 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005462 else
5463 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5464 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005465 let ret= v:shell_error
5466
Bram Moolenaar97d62492012-11-15 21:28:22 +01005467 elseif has("win32unix")
5468 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005469" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005470 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005472 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005473 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005474" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005475 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005476 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005477" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005478 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005479 else
5480 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5481 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005482 let ret= v:shell_error
5483
Bram Moolenaar85850f32019-07-19 22:05:51 +02005484 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005485" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5486 if a:fname =~ '^https\=://'
5487 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5488 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005489" call Decho("fname<".fname.">")
5490" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005491 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5492
5493 else
5494 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5495 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005496 let ret= v:shell_error
5497
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005498 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5499" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5500 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5501 let ret= v:shell_error
5502
5503 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5504" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5505 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5506 let ret= v:shell_error
5507
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005508 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005509" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005510 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005511 let ret= v:shell_error
5512
5513 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005514" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005515 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005516 let ret= v:shell_error
5517
5518 else
5519 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005520" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005521 let ret= netrwFileHandlers#Invoke(exten,fname)
5522 endif
5523
5524 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5525 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005526" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005527 let ret= netrwFileHandlers#Invoke(exten,fname)
5528 endif
5529
Bram Moolenaarc236c162008-07-13 17:41:49 +00005530 " restoring redraw! after external file handlers
5531 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005532
5533 " cleanup: remove temporary file,
5534 " delete current buffer if success with handler,
5535 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005536 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005537 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005538" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005539"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005540" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541" endif
5542
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005543 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005544 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005546 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005548 if use_ctrlo
5549 exe "sil! NetrwKeepj norm! \<c-o>"
5550 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005552" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005553 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005554 let @@ = ykeep
5555 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005556
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005557" call Dret("netrw#BrowseX")
5558endfun
5559
5560" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005561" netrw#GX: gets word under cursor for gx support {{{2
5562" See also: netrw#BrowseXVis
5563" netrw#BrowseX
5564fun! netrw#GX()
5565" call Dfunc("netrw#GX()")
5566 if &ft == "netrw"
5567 let fname= s:NetrwGetWord()
5568 else
5569 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5570 endif
5571" call Dret("netrw#GX <".fname.">")
5572 return fname
5573endfun
5574
5575" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005576" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5577fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005578 let dict={}
5579 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005580 norm! gv"ay
5581 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005582 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005583 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005584endfun
5585
5586" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005587" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5588" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5589" to become an unlisted buffer, so in that case don't bwipe it.
5590fun! s:NetrwBufRename(newname)
5591" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5592" call Dredir("ls!","s:NetrwBufRename (before rename)")
5593 let oldbufname= bufname(bufnr("%"))
5594" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5595
5596 if oldbufname != a:newname
5597" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5598 let b:junk= 1
5599" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5600 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005601" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005602 let oldbufnr= bufnr(oldbufname)
5603" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5604" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5605 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5606" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5607 exe "bwipe! ".oldbufnr
5608" else " Decho
5609" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005610" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5611" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5612" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005613 endif
5614" call Dredir("ls!","s:NetrwBufRename (after rename)")
5615" else " Decho
5616" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5617 endif
5618
5619" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5620endfun
5621
5622" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005623" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005624fun! netrw#CheckIfRemote(...)
5625" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5626 if a:0 > 0
5627 let curfile= a:1
5628 else
5629 let curfile= expand("%")
5630 endif
5631" call Decho("curfile<".curfile.">")
5632 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005633" call Dret("netrw#CheckIfRemote 1")
5634 return 1
5635 else
5636" call Dret("netrw#CheckIfRemote 0")
5637 return 0
5638 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005639endfun
5640
5641" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005642" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5643fun! s:NetrwChgPerm(islocal,curdir)
5644" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005645 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005646 call inputsave()
5647 let newperm= input("Enter new permission: ")
5648 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005649 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5650 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5651" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005652 call system(chgperm)
5653 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005654 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 endif
5656 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005657 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005659 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005660" call Dret("s:NetrwChgPerm")
5661endfun
5662
5663" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005664" s:CheckIfKde: checks if kdeinit is running {{{2
5665" Returns 0: kdeinit not running
5666" 1: kdeinit is running
5667fun! s:CheckIfKde()
5668" call Dfunc("s:CheckIfKde()")
5669 " seems kde systems often have gnome-open due to dependencies, even though
5670 " gnome-open's subsidiary display tools are largely absent. Kde systems
5671 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5672 if !exists("s:haskdeinit")
5673 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005674 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005675 if v:shell_error
5676 let s:haskdeinit = 0
5677 endif
5678 else
5679 let s:haskdeinit= 0
5680 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005681" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005682 endif
5683
5684" call Dret("s:CheckIfKde ".s:haskdeinit)
5685 return s:haskdeinit
5686endfun
5687
5688" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005689" s:NetrwClearExplore: clear explore variables (if any) {{{2
5690fun! s:NetrwClearExplore()
5691" call Dfunc("s:NetrwClearExplore()")
5692 2match none
5693 if exists("s:explore_match") |unlet s:explore_match |endif
5694 if exists("s:explore_indx") |unlet s:explore_indx |endif
5695 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5696 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5697 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5698 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5699 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5700 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5701 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5702" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005703" call Dret("s:NetrwClearExplore")
5704endfun
5705
5706" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005707" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5708fun! s:NetrwEditBuf(bufnum)
5709" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5710 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5711" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5712 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5713 else
5714" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005715 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005716 endif
5717" call Dret("s:NetrwEditBuf")
5718endfun
5719
5720" ---------------------------------------------------------------------
5721" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5722" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5723fun! s:NetrwEditFile(cmd,opt,fname)
5724" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5725 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5726" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5727 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5728 else
5729" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005730 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5731 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5732 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005733 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5734 endif
5735" call Dret("s:NetrwEditFile")
5736endfun
5737
5738" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005739" s:NetrwExploreListUniq: {{{2
5740fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005741" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005742
5743 " this assumes that the list is already sorted
5744 let newexplist= []
5745 for member in a:explist
5746 if !exists("uniqmember") || member != uniqmember
5747 let uniqmember = member
5748 let newexplist = newexplist + [ member ]
5749 endif
5750 endfor
5751
Bram Moolenaar15146672011-10-20 22:22:38 +02005752" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005753 return newexplist
5754endfun
5755
5756" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005757" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5758fun! s:NetrwForceChgDir(islocal,newdir)
5759" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005760 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005761 if a:newdir !~ '/$'
5762 " ok, looks like force is needed to get directory-style treatment
5763 if a:newdir =~ '@$'
5764 let newdir= substitute(a:newdir,'@$','/','')
5765 elseif a:newdir =~ '[*=|\\]$'
5766 let newdir= substitute(a:newdir,'.$','/','')
5767 else
5768 let newdir= a:newdir.'/'
5769 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005770" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005771 else
5772 " should already be getting treatment as a directory
5773 let newdir= a:newdir
5774 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005775 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005776 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005777 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005778" call Dret("s:NetrwForceChgDir")
5779endfun
5780
5781" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005782" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005783" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5784" expr : this is the expression to follow the directory. Will use s:ComposePath()
5785" pare =1: remove the current directory from the resulting glob() filelist
5786" =0: leave the current directory in the resulting glob() filelist
5787fun! s:NetrwGlob(direntry,expr,pare)
5788" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005789 if netrw#CheckIfRemote()
5790 keepalt 1sp
5791 keepalt enew
5792 let keep_liststyle = w:netrw_liststyle
5793 let w:netrw_liststyle = s:THINLIST
5794 if s:NetrwRemoteListing() == 0
5795 keepj keepalt %s@/@@
5796 let filelist= getline(1,$)
5797 q!
5798 else
5799 " remote listing error -- leave treedict unchanged
5800 let filelist= w:netrw_treedict[a:direntry]
5801 endif
5802 let w:netrw_liststyle= keep_liststyle
5803 else
Christian Brabandt14879472024-06-13 21:25:35 +02005804 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005805 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005806 " escape [ so it is not detected as wildcard character, see :h wildcard
5807 let path= substitute(path, '[', '[[]', 'g')
5808 endif
5809 if v:version > 704 || (v:version == 704 && has("patch656"))
5810 let filelist= glob(path,0,1,1)
5811 else
5812 let filelist= glob(path,0,1)
5813 endif
5814 if a:pare
5815 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5816 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005817 endif
5818" call Dret("s:NetrwGlob ".string(filelist))
5819 return filelist
5820endfun
5821
5822" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005823" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5824fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005825" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005826 if a:newfile =~ '[/@*=|\\]$'
5827 let newfile= substitute(a:newfile,'.$','','')
5828 else
5829 let newfile= a:newfile
5830 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005831 if a:islocal
5832 call s:NetrwBrowseChgDir(a:islocal,newfile)
5833 else
5834 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5835 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005836" call Dret("s:NetrwForceFile")
5837endfun
5838
5839" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005840" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5841" and switches the hiding mode. The actual hiding is done by
5842" s:NetrwListHide().
5843" g:netrw_hide= 0: show all
5844" 1: show not-hidden files
5845" 2: show hidden files only
5846fun! s:NetrwHide(islocal)
5847" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005848 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005849 let svpos= winsaveview()
5850" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005851
5852 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005853" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5854" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005855
5856 " hide the files in the markfile list
5857 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005858" 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 +00005859 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5860 " remove fname from hiding list
5861 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5862 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5863 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005864" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005865 else
5866 " append fname to hiding list
5867 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5868 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5869 else
5870 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5871 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005872" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873 endif
5874 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005875 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005876 let g:netrw_hide= 1
5877
5878 else
5879
5880 " switch between show-all/show-not-hidden/show-hidden
5881 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005882 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005883 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005884 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005885 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005886" call Dret("NetrwHide")
5887 return
5888 endif
5889 endif
5890
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005891 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005892" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5893 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005894 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005896endfun
5897
5898" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005899" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5900fun! s:NetrwHideEdit(islocal)
5901" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5902
5903 let ykeep= @@
5904 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005905 let svpos= winsaveview()
5906" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005907
5908 " get new hiding list from user
5909 call inputsave()
5910 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5911 call inputrestore()
5912 let g:netrw_list_hide= newhide
5913" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5914
5915 " refresh the listing
5916 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5917
5918 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005919" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5920 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005921 let @@= ykeep
5922
5923" call Dret("NetrwHideEdit")
5924endfun
5925
5926" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927" s:NetrwHidden: invoked by "gh" {{{2
5928fun! s:NetrwHidden(islocal)
5929" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005930 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005932 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005933" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934
5935 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936 " remove .file pattern from hiding list
5937" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005939 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005940" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005941 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5942 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005943" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005944 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5945 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005946 if g:netrw_list_hide =~ '^,'
5947 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949
5950 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005951 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005952" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5953 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005954 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005955" call Dret("s:NetrwHidden")
5956endfun
5957
5958" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005959" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5960fun! s:NetrwHome()
5961 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005962 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005963 else
5964 " go to vim plugin home
5965 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005966 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005967 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005968 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005969 let home= basehome."/.vim"
5970 break
5971 endif
5972 endfor
5973 if home == ""
5974 " just pick the first directory
5975 let home= substitute(&rtp,',.*$','','')
5976 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005977 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005978 let home= substitute(home,'/','\\','g')
5979 endif
5980 endif
5981 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005982 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005983" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005984 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005985" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005986 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005987 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005988" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005989 call mkdir(home)
5990 endif
5991 endif
5992 let g:netrw_home= home
5993 return home
5994endfun
5995
5996" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005997" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5998fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005999 if exists("s:netrwdrag")
6000 return
6001 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006002 if &ft != "netrw"
6003 return
6004 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006005" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006006
Bram Moolenaar97d62492012-11-15 21:28:22 +01006007 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006008 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006009 while getchar(0) != 0
6010 "clear the input stream
6011 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006012 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006013 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006014 let mouse_lnum = v:mouse_lnum
6015 let wlastline = line('w$')
6016 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006017" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6018" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006019 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6020 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006021 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006022" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6023 return
6024 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006025 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006026 " 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 +01006027 " without this test when its disabled.
6028 " 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 +01006029" 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 +01006030 if v:mouse_col > virtcol('.')
6031 let @@= ykeep
6032" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6033 return
6034 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006035
Bram Moolenaar446cb832008-06-24 21:56:24 +00006036 if a:islocal
6037 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006038 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006039 endif
6040 else
6041 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006042 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006043 endif
6044 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006045 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006046" call Dret("s:NetrwLeftmouse")
6047endfun
6048
6049" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006050" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6051fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006052 if &ft != "netrw"
6053 return
6054 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006055" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6056 call s:NetrwMarkFileTgt(a:islocal)
6057" call Dret("s:NetrwCLeftmouse")
6058endfun
6059
6060" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6062" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006063" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006064" a:islocal=2 : <c-r> used, remote
6065" a:islocal=3 : <c-r> used, local
6066fun! s:NetrwServerEdit(islocal,fname)
6067" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6068 let islocal = a:islocal%2 " =0: remote =1: local
6069 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006070" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006071
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006072 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006073 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006074 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006075" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006076 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006077 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006078 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6079 unlet s:netrw_browse_split_{winnr()}
6080 endif
6081 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6082" call Dret("s:NetrwServerEdit")
6083 return
6084 endif
6085
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006086" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006087 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006088" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006089
6090 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006091" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006092 let srvrname = g:netrw_browse_split[0]
6093 let tabnum = g:netrw_browse_split[1]
6094 let winnum = g:netrw_browse_split[2]
6095
6096 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006097" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006098
6099 if !ctrlr
6100 " user must have closed the server window and the user did not use <c-r>, but
6101 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006102" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006103 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006104 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006105 endif
6106 let g:netrw_browse_split= 0
6107 if exists("s:netrw_browse_split_".winnr())
6108 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6109 endif
6110 call s:NetrwBrowseChgDir(islocal,a:fname)
6111" call Dret("s:NetrwServerEdit")
6112 return
6113
6114 elseif has("win32") && executable("start")
6115 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006116" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006117 call system("start gvim --servername ".srvrname)
6118
6119 else
6120 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006121" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006122 call system("gvim --servername ".srvrname)
6123 endif
6124 endif
6125
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6128 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006129 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006130
6131 else
6132
6133 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6134
6135 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006136" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006137 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006138 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006139 endif
6140 let g:netrw_browse_split= 0
6141 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6142" call Dret("s:NetrwServerEdit")
6143 return
6144
6145 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006147 if has("win32") && executable("start")
6148 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150 call system("start gvim --servername ".g:netrw_servername)
6151 else
6152 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006153" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006154 call system("gvim --servername ".g:netrw_servername)
6155 endif
6156 endif
6157 endif
6158
6159 while 1
6160 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6162 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006163 break
6164 catch /^Vim\%((\a\+)\)\=:E241/
6165 sleep 200m
6166 endtry
6167 endwhile
6168
6169 if exists("g:netrw_browse_split")
6170 if type(g:netrw_browse_split) != 3
6171 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6172 endif
6173 unlet g:netrw_browse_split
6174 endif
6175 let g:netrw_browse_split= [g:netrw_servername,1,1]
6176 endif
6177
6178 else
6179 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6180 endif
6181
6182" call Dret("s:NetrwServerEdit")
6183endfun
6184
6185" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006186" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6187fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006188 if &ft != "netrw"
6189 return
6190 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006191" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006192
Bram Moolenaar8d043172014-01-23 14:24:41 +01006193 let s:ngw= s:NetrwGetWord()
6194 call s:NetrwMarkFile(a:islocal,s:ngw)
6195
6196" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006197endfun
6198
6199" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006200" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6201" Used to mark multiple files.
6202fun! s:NetrwSLeftdrag(islocal)
6203" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6204 if !exists("s:netrwdrag")
6205 let s:netrwdrag = winnr()
6206 if a:islocal
6207 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006208 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006209 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006210 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006211 endif
6212 let ngw = s:NetrwGetWord()
6213 if !exists("s:ngw") || s:ngw != ngw
6214 call s:NetrwMarkFile(a:islocal,ngw)
6215 endif
6216 let s:ngw= ngw
6217" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6218endfun
6219
6220" ---------------------------------------------------------------------
6221" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6222fun! s:NetrwSLeftrelease(islocal)
6223" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6224 if exists("s:netrwdrag")
6225 nunmap <s-leftrelease>
6226 let ngw = s:NetrwGetWord()
6227 if !exists("s:ngw") || s:ngw != ngw
6228 call s:NetrwMarkFile(a:islocal,ngw)
6229 endif
6230 if exists("s:ngw")
6231 unlet s:ngw
6232 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006233 unlet s:netrwdrag
6234 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006235" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006236endfun
6237
6238" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006239" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6240" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006241fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006242" 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 +02006243" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006244 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006245
6246 " 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 +02006247 " How-it-works: take the hiding command, convert it into a range.
6248 " Duplicate characters don't matter.
6249 " Remove all such characters from the '/~@#...890' string.
6250 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006251" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006253 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006254" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006255
6256 while listhide != ""
6257 if listhide =~ ','
6258 let hide = substitute(listhide,',.*$','','e')
6259 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6260 else
6261 let hide = listhide
6262 let listhide = ""
6263 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006264" 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 +01006265 if g:netrw_sort_by =~ '^[ts]'
6266 if hide =~ '^\^'
6267" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6268 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6269 elseif hide =~ '^\\(\^'
6270 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6271 endif
6272" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6273 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274
6275 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006276" 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 +00006277 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006278" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006279 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006280 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006281" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006282 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006284" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006286
Bram Moolenaar446cb832008-06-24 21:56:24 +00006287 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006288 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006289" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006290 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006291" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006292 endif
6293
Bram Moolenaaradc21822011-04-01 18:03:16 +02006294 " remove any blank lines that have somehow remained.
6295 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006296 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006297
Bram Moolenaar97d62492012-11-15 21:28:22 +01006298 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006299" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300endfun
6301
6302" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006304" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006306" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307
Bram Moolenaar97d62492012-11-15 21:28:22 +01006308 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 " get name of new directory from user. A bare <CR> will skip.
6310 " if its currently a directory, also request will be skipped, but with
6311 " a message.
6312 call inputsave()
6313 let newdirname= input("Please give directory name: ")
6314 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006315" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316
6317 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006318 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006319" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006320 return
6321 endif
6322
6323 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006324" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325
6326 " Local mkdir:
6327 " sanity checks
6328 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006329" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6330 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006332 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006334 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006335" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006336 return
6337 endif
6338 if s:FileReadable(fullnewdir)
6339 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006340 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006341 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006342 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006343" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006344 return
6345 endif
6346
6347 " requested new local directory is neither a pre-existing file or
6348 " directory, so make it!
6349 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006350 if has("unix")
6351 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6352 else
6353 call mkdir(fullnewdir,"p")
6354 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006355 else
6356 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006357 if s:NetrwLcd(b:netrw_curdir)
6358" call Dret("s:NetrwMakeDir : lcd failure")
6359 return
6360 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006361" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006362 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006363 if v:shell_error != 0
6364 let @@= ykeep
6365 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 +01006366" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006367 return
6368 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006369 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006370" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006371 if s:NetrwLcd(netrw_origdir)
6372" call Dret("s:NetrwBrowse : lcd failure")
6373 return
6374 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006375 endif
6376 endif
6377
6378 if v:shell_error == 0
6379 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006380" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006381 let svpos= winsaveview()
6382" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006383 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006384" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6385 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006386 elseif !exists("g:netrw_quiet")
6387 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6388 endif
6389" redraw!
6390
6391 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006392 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006393" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006394 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6395 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006396 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006397 if v:shell_error == 0
6398 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006399 let svpos= winsaveview()
6400" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006401 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006402" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6403 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006404 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006405 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006406 endif
6407" redraw!
6408
6409 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006411 let svpos= winsaveview()
6412" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006413" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006414 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006415" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006416 let remotepath= b:netrw_fname
6417 else
6418 let remotepath= ""
6419 endif
6420 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006421 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006422" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6423 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006424
Bram Moolenaar446cb832008-06-24 21:56:24 +00006425 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006427 let svpos= winsaveview()
6428" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006429" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006430 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006432 let remotepath= b:netrw_fname
6433 else
6434 let remotepath= ""
6435 endif
6436 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006437 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006438" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6439 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006440 endif
6441
Bram Moolenaar97d62492012-11-15 21:28:22 +01006442 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006443" call Dret("s:NetrwMakeDir")
6444endfun
6445
6446" ---------------------------------------------------------------------
6447" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6448fun! s:TreeSqueezeDir(islocal)
6449" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6450 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6451 " its a tree-listing style
6452 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006453 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006454 let depth = strchars(substitute(curdepth,' ','','g'))
6455 let srch = -1
6456" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6457" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006458" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006459" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6460 if depth >= 2
6461 NetrwKeepj norm! 0
6462 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6463 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6464" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6465" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6466 elseif depth == 1
6467 NetrwKeepj norm! 0
6468 let treedepthchr= substitute(s:treedepthstring,' ','','')
6469 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6470" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6471 endif
6472 if srch > 0
6473" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6474 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6475 exe srch
6476 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006477 endif
6478" call Dret("s:TreeSqueezeDir")
6479endfun
6480
6481" ---------------------------------------------------------------------
6482" s:NetrwMaps: {{{2
6483fun! s:NetrwMaps(islocal)
6484" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6485
Bram Moolenaar85850f32019-07-19 22:05:51 +02006486 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006487 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006488" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 if !hasmapto("<Plug>NetrwReturn")
6490 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006491" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006492 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6493 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006494" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006495 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6496 endif
6497 endif
6498 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006499" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006500 endif
6501
Bram Moolenaar85850f32019-07-19 22:05:51 +02006502 " generate default <Plug> maps {{{3
6503 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006504 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006505 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6506 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6507 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6508 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6509 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6510 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6511 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6512 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6513 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6514 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6515" ---------------------------------------------------------------------
6516" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6517" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6518" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6519" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6520" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6521" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6522" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6523" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6524" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6525" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6526" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6527" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6528" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6529" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6530" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6531" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6532" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6533" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6534" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6535" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6536" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6537" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6538" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6539" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6540" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6541" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6542" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6543" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6544" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6545" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6546" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6547" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6548" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6549" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6550" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6551" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6552" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6553" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6554" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6555" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6556" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6557" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6558" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6559" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6560" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6561" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6562" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6563
Bram Moolenaara6878372014-03-22 21:02:50 +01006564 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006565" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006566 " local normal-mode maps {{{3
6567 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6577 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6578" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006579 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6580 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6581 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006582 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006583 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006584 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6586 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6587 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006588 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6589 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6590 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6591 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6594 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6595 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006601 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006602 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6604 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6605 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6606 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6607 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006608 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006609 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006610 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6611 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6613 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6614 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006615 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006617 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6618 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006619 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006620 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6622 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6623 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6625 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006626
6627 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 +01006628 if !hasmapto('<Plug>NetrwHideEdit')
6629 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006630 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006631 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 if !hasmapto('<Plug>NetrwRefresh')
6633 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006634 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006635 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 +01006636 if s:didstarstar || !mapcheck("<s-down>","n")
6637 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006638 endif
6639 if s:didstarstar || !mapcheck("<s-up>","n")
6640 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006641 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006642 if !hasmapto('<Plug>NetrwTreeSqueeze')
6643 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006644 endif
6645 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006646 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6647 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006648 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6649 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6650 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6651 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6652 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6653 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6654 imap <buffer> <leftmouse> <Plug>ILeftmouse
6655 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006656 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6657 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6658 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6659 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6660 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006662 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6663 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006664 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006665 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6667 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6668 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6669 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6670 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6671 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006672 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6673
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006674 " support user-specified maps
6675 call netrw#UserMaps(1)
6676
Bram Moolenaar85850f32019-07-19 22:05:51 +02006677 else
6678 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006679" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006680 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006681 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6691 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6692" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006693 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6694 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6695 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6696 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6697 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6698 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6699 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6700 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006702 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6704 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6707 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6708 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006715 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6719 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6720 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006721 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6723 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6724 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006726 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6727 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006728 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006729 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 +01006730 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6733 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6734 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6735 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6736 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6737 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6738 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006739 if !hasmapto('<Plug>NetrwHideEdit')
6740 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006741 endif
6742 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6743 if !hasmapto('<Plug>NetrwRefresh')
6744 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006745 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006746 if !hasmapto('<Plug>NetrwTreeSqueeze')
6747 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006748 endif
6749 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006750
6751 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006752 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006753
6754 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6755 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006757 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006759 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006761 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006763 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006764 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006765 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6767 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6768 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006771 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6772 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006773 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006774 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6775 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6776 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6777 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6778 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6780 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006781 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006782
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006783 " support user-specified maps
6784 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006785 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006786
6787" call Dret("s:NetrwMaps")
6788endfun
6789
6790" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006791" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006792" If -buffer, the command is only available from within netrw buffers
6793" Otherwise, the command is available from any window, so long as netrw
6794" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006795fun! s:NetrwCommands(islocal)
6796" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6797
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006798 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6799 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006800 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 +01006801 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006802 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006803 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006804 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006805 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006806 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006807
6808" call Dret("s:NetrwCommands")
6809endfun
6810
6811" ---------------------------------------------------------------------
6812" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6813" glob()ing only works with local files
6814fun! s:NetrwMarkFiles(islocal,...)
6815" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006816 let curdir = s:NetrwGetCurdir(a:islocal)
6817 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006818 while i <= a:0
6819 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006820 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006821 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006822 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006823 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006825 else
6826 let mffiles= [a:{i}]
6827 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006828" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006829 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006830" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006831 call s:NetrwMarkFile(a:islocal,mffile)
6832 endfor
6833 let i= i + 1
6834 endwhile
6835" call Dret("s:NetrwMarkFiles")
6836endfun
6837
6838" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006840fun! s:NetrwMarkTarget(...)
6841" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6842 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006843 let curdir = s:NetrwGetCurdir(1)
6844 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006845 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006846 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6847 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006848 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006849" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006850 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6852 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006853 let svpos = winsaveview()
6854" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006856" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6857 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006858" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006859endfun
6860
6861" ---------------------------------------------------------------------
6862" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6863" mark and unmark files. If a markfile list exists,
6864" then the rename and delete functions will use it instead
6865" of whatever may happen to be under the cursor at that
6866" moment. When the mouse and gui are available,
6867" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006868"
6869" Creates two lists
6870" s:netrwmarkfilelist -- holds complete paths to all marked files
6871" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6872"
6873" Creates a marked file match string
6874" s:netrwmarfilemtch_# -- used with 2match to display marked files
6875"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006876" Creates a buffer version of islocal
6877" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006878fun! s:NetrwMarkFile(islocal,fname)
6879" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006880" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006881
6882 " sanity check
6883 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006884" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006885 return
6886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006887 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006888
Bram Moolenaar97d62492012-11-15 21:28:22 +01006889 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006890 let curbufnr= bufnr("%")
yasuda38cfa2b2024-08-22 20:54:47 +02006891 let leader= '\(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006892 if a:fname =~ '\a$'
6893 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6894 else
6895 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6896 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006897
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006899 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6901" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6902" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006903 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904
6905 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006909 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910
6911 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006912 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6915 if s:netrwmarkfilelist_{curbufnr} == []
6916 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006917" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 call s:NetrwUnmarkList(curbufnr,curdir)
6919 else
6920 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006921" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006923 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 for fname in s:netrwmarkfilelist_{curbufnr}
6925 if first
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 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006928 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929 endif
6930 let first= 0
6931 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 endif
6934 endif
6935
6936 else
6937 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006938" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006939
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6943" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944
6945 " build initial markfile matching pattern
6946 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006947 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006949 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 endif
6953
6954 " handle global markfilelist
6955 if exists("s:netrwmarkfilelist")
6956 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6957 if index(s:netrwmarkfilelist,dname) == -1
6958 " append new filename to global markfilelist
6959 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 else
6962 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6964" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006968" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 unlet s:netrwmarkfilelist
6970 endif
6971 endif
6972 else
6973 " initialize new global-directory markfilelist
6974 let s:netrwmarkfilelist= []
6975 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006976" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977 endif
6978
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006980 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6981 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6982" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6983 if exists("g:did_drchip_netrwlist_syntax")
6984 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6985 endif
6986 else
6987" " call Decho("2match none",'~'.expand("<slnum>"))
6988 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006990 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006991 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006992" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6993" 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 +00006994endfun
6995
6996" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006997" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6998" mA: move the argument list to marked file list (tomflist=1)
6999" Uses the global marked file list
7000fun! s:NetrwMarkFileArgList(islocal,tomflist)
7001" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7002
7003 let svpos = winsaveview()
7004" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7005 let curdir = s:NetrwGetCurdir(a:islocal)
7006 let curbufnr = bufnr("%")
7007
7008 if a:tomflist
7009 " mA: move argument list to marked file list
7010 while argc()
7011 let fname= argv(0)
7012" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7013 exe "argdel ".fnameescape(fname)
7014 call s:NetrwMarkFile(a:islocal,fname)
7015 endwhile
7016
7017 else
7018 " ma: move marked file list to argument list
7019 if exists("s:netrwmarkfilelist")
7020
7021 " for every filename in the marked list
7022 for fname in s:netrwmarkfilelist
7023" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7024 exe "argadd ".fnameescape(fname)
7025 endfor " for every file in the marked list
7026
7027 " unmark list and refresh
7028 call s:NetrwUnmarkList(curbufnr,curdir)
7029 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7030" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7031 NetrwKeepj call winrestview(svpos)
7032 endif
7033 endif
7034
7035" call Dret("s:NetrwMarkFileArgList")
7036endfun
7037
7038" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007039" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7040" compress/decompress files using the programs
7041" in g:netrw_compress and g:netrw_uncompress,
7042" using g:netrw_compress_suffix to know which to
7043" do. By default:
7044" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007045" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007046fun! s:NetrwMarkFileCompress(islocal)
7047" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007048 let svpos = winsaveview()
7049" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007050 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007051 let curbufnr = bufnr("%")
7052
Bram Moolenaarff034192013-04-24 18:51:19 +02007053 " sanity check
7054 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007055 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007056" call Dret("s:NetrwMarkFileCompress")
7057 return
7058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007059" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007060
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007062
7063 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007065 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007067 if exists("g:netrw_decompress['".sfx."']")
7068 " fname has a suffix indicating that its compressed; apply associated decompression routine
7069 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007071 let exe= netrw#WinPath(exe)
7072 if a:islocal
7073 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007074 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007076 call system(exe." ".fname)
7077 if v:shell_error
7078 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007079 endif
7080 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007081 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7082 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007083 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084
Bram Moolenaarff034192013-04-24 18:51:19 +02007085 endif
7086 unlet sfx
7087
Bram Moolenaar446cb832008-06-24 21:56:24 +00007088 if exists("exe")
7089 unlet exe
7090 elseif a:islocal
7091 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007093 if v:shell_error
7094 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 else
7097 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007098 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007100 endfor " for every file in the marked list
7101
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007103 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007104" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7105 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007106 endif
7107" call Dret("s:NetrwMarkFileCompress")
7108endfun
7109
7110" ---------------------------------------------------------------------
7111" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7112" If no marked files, then set up directory as the
7113" target. Currently does not support copying entire
7114" directories. Uses the local-buffer marked file list.
7115" Returns 1=success (used by NetrwMarkFileMove())
7116" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007117fun! s:NetrwMarkFileCopy(islocal,...)
7118" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7119
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007120 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007121 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007122 if b:netrw_curdir !~ '/$'
7123 if !exists("b:netrw_curdir")
7124 let b:netrw_curdir= curdir
7125 endif
7126 let b:netrw_curdir= b:netrw_curdir."/"
7127 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128
Bram Moolenaarff034192013-04-24 18:51:19 +02007129 " sanity check
7130 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007131 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007132" call Dret("s:NetrwMarkFileCopy")
7133 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007135" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007136
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139" call Dret("s:NetrwMarkFileCopy 0")
7140 return 0
7141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007142" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007143
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007144 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007145 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007146" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007147 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007148 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7149" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7150 return
7151 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007152
7153 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007154 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7156 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007158 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7160 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007163 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007164 let oldname = a:1
7165 else
7166 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007167" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007168 let s:recursive= 1
7169 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7170 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7171 if ret == 0
7172 break
7173 endif
7174 endfor
7175 unlet s:recursive
7176 call s:NetrwUnmarkList(curbufnr,curdir)
7177" call Dret("s:NetrwMarkFileCopy ".ret)
7178 return ret
7179 endif
7180
7181 call inputsave()
7182 let newname= input("Copy ".oldname." to : ",oldname,"file")
7183 call inputrestore()
7184 if newname == ""
7185" call Dret("s:NetrwMarkFileCopy 0")
7186 return 0
7187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007188 let args= s:ShellEscape(oldname)
7189 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007190 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7192 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007194 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007195 let args= substitute(args,'/','\\','g')
7196 let tgt = substitute(tgt, '/','\\','g')
7197 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007198 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7199 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7200 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7201 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7202" call Decho("args <".args.">",'~'.expand("<slnum>"))
7203" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 if isdirectory(s:NetrwFile(args))
7205" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007208 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7210 " contents to a target. One must append the source directory name to the target to get xcopy to
7211 " do the right thing.
7212 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007213" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007214 endif
7215 else
7216 let copycmd= g:netrw_localcopycmd
7217 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007219 let copycmd = substitute(copycmd,'\s.*$','','')
7220 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 let copycmd = netrw#WinPath(copycmd).copycmdargs
7222 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007223 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225" call Decho("args <".args.">",'~'.expand("<slnum>"))
7226" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7227" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7228" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007229 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007230 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007231 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 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 +01007233 else
7234 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7235 endif
7236" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007237 return 0
7238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239
7240 elseif a:islocal && !s:netrwmftgt_islocal
7241 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007242" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007243 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244
7245 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007246 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007247" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007248 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007249
7250 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007251 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007252" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253 let curdir = getcwd()
7254 let tmpdir = s:GetTempfile("")
7255 if tmpdir !~ '/'
7256 let tmpdir= curdir."/".tmpdir
7257 endif
7258 if exists("*mkdir")
7259 call mkdir(tmpdir)
7260 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007261 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007262 if v:shell_error != 0
7263 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 +01007264" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 return
7266 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007268 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007269 if s:NetrwLcd(tmpdir)
7270" call Dret("s:NetrwMarkFileCopy : lcd failure")
7271 return
7272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007273 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007274 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 if getcwd() == tmpdir
7277 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007280 if s:NetrwLcd(curdir)
7281" call Dret("s:NetrwMarkFileCopy : lcd failure")
7282 return
7283 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007284 if delete(tmpdir,"d")
7285 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007287 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007288 if s:NetrwLcd(curdir)
7289" call Dret("s:NetrwMarkFileCopy : lcd failure")
7290 return
7291 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 endif
7293 endif
7294 endif
7295
7296 " -------
7297 " cleanup
7298 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007299" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007300 " remove markings from local buffer
7301 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7303" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7304" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7305" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7306" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7307" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7308 if exists("s:recursive")
7309" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7310 else
7311" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007312 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007313 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007314 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007315 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 else
7317 " refresh local and targets for fast browsing
7318 if !exists("s:recursive")
7319 " remove markings from local buffer
7320" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7321 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7322 endif
7323
7324 " refresh buffers
7325 if s:netrwmftgt_islocal
7326" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7327 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7328 endif
7329 if a:islocal && s:netrwmftgt != curdir
7330" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7331 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7332 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007334
Bram Moolenaar446cb832008-06-24 21:56:24 +00007335" call Dret("s:NetrwMarkFileCopy 1")
7336 return 1
7337endfun
7338
7339" ---------------------------------------------------------------------
7340" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7341" invoke vim's diff mode on the marked files.
7342" Either two or three files can be so handled.
7343" Uses the global marked file list.
7344fun! s:NetrwMarkFileDiff(islocal)
7345" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7346 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007347
Bram Moolenaarff034192013-04-24 18:51:19 +02007348 " sanity check
7349 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007350 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007351" call Dret("s:NetrwMarkFileDiff")
7352 return
7353 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354 let curdir= s:NetrwGetCurdir(a:islocal)
7355" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007356
Bram Moolenaara6878372014-03-22 21:02:50 +01007357 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007359 for fname in s:netrwmarkfilelist
7360 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007362" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007363 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 diffthis
7365 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007366 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007368 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369 diffthis
7370 else
7371 break
7372 endif
7373 endfor
7374 call s:NetrwUnmarkList(curbufnr,curdir)
7375 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007376
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377" call Dret("s:NetrwMarkFileDiff")
7378endfun
7379
7380" ---------------------------------------------------------------------
7381" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7382" Uses global markfilelist
7383fun! s:NetrwMarkFileEdit(islocal)
7384" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7385
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007388
7389 " sanity check
7390 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007392" call Dret("s:NetrwMarkFileEdit")
7393 return
7394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007396
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 if exists("s:netrwmarkfilelist_{curbufnr}")
7398 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007399 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 " unmark markedfile list
7401" call s:NetrwUnmarkList(curbufnr,curdir)
7402 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007403" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007404 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007406 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007407
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408" call Dret("s:NetrwMarkFileEdit")
7409endfun
7410
7411" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007412" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007413fun! s:NetrwMarkFileQFEL(islocal,qfel)
7414" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7415 call s:NetrwUnmarkAll()
7416 let curbufnr= bufnr("%")
7417
7418 if !empty(a:qfel)
7419 for entry in a:qfel
7420 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007422 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007424 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7425 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7426 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7427 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007429 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7430 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 endif
7433 endfor
7434 echo "(use me to edit marked files)"
7435 else
7436 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7437 endif
7438
7439" call Dret("s:NetrwMarkFileQFEL")
7440endfun
7441
7442" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007443" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7444" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7445" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7446fun! s:NetrwMarkFileExe(islocal,enbloc)
7447" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007448 let svpos = winsaveview()
7449" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007450 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 let curbufnr = bufnr("%")
7452
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453 if a:enbloc == 0
7454 " individually apply command to files, one at a time
7455 " sanity check
7456 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7457 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7458" call Dret("s:NetrwMarkFileExe")
7459 return
7460 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007462
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 if exists("s:netrwmarkfilelist_{curbufnr}")
7464 " get the command
7465 call inputsave()
7466 let cmd= input("Enter command: ","","file")
7467 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007468" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007469 if cmd == ""
7470" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7471 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007472 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007473
7474 " apply command to marked files, individually. Substitute: filename -> %
7475 " If no %, then append a space and the filename to the command
7476 for fname in s:netrwmarkfilelist_{curbufnr}
7477 if a:islocal
7478 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007479 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007480 endif
7481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 if cmd =~ '%'
7485 let xcmd= substitute(cmd,'%',fname,'g')
7486 else
7487 let xcmd= cmd.' '.fname
7488 endif
7489 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007490" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 let ret= system(xcmd)
7492 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= s:RemoteSystem(xcmd)
7495 endif
7496 if v:shell_error < 0
7497 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7498 break
7499 else
7500 echo ret
7501 endif
7502 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503
7504 " unmark marked file list
7505 call s:NetrwUnmarkList(curbufnr,curdir)
7506
7507 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007509" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7510 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514
7515 else " apply command to global list of files, en bloc
7516
7517 call inputsave()
7518 let cmd= input("Enter command: ","","file")
7519 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 if cmd == ""
7522" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7523 return
7524 endif
7525 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007526 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007528 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 endif
7530 if a:islocal
7531 call system(cmd)
7532 if v:shell_error < 0
7533 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7534 endif
7535 else
7536 let ret= s:RemoteSystem(cmd)
7537 endif
7538 call s:NetrwUnmarkAll()
7539
7540 " refresh the listing
7541 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007542" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7543 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007544
7545 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007546
Bram Moolenaar446cb832008-06-24 21:56:24 +00007547" call Dret("s:NetrwMarkFileExe")
7548endfun
7549
7550" ---------------------------------------------------------------------
7551" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7552" as the marked file(s) (toggles suffix presence)
7553" Uses the local marked file list.
7554fun! s:NetrwMarkHideSfx(islocal)
7555" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007556 let svpos = winsaveview()
7557" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007558 let curbufnr = bufnr("%")
7559
7560 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7561 if exists("s:netrwmarkfilelist_{curbufnr}")
7562
7563 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007564" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007565 " construct suffix pattern
7566 if fname =~ '\.'
7567 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7568 else
7569 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7570 endif
7571 " determine if its in the hiding list or not
7572 let inhidelist= 0
7573 if g:netrw_list_hide != ""
7574 let itemnum = 0
7575 let hidelist= split(g:netrw_list_hide,',')
7576 for hidepat in hidelist
7577 if sfxpat == hidepat
7578 let inhidelist= 1
7579 break
7580 endif
7581 let itemnum= itemnum + 1
7582 endfor
7583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007584" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007585 if inhidelist
7586 " remove sfxpat from list
7587 call remove(hidelist,itemnum)
7588 let g:netrw_list_hide= join(hidelist,",")
7589 elseif g:netrw_list_hide != ""
7590 " append sfxpat to non-empty list
7591 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7592 else
7593 " set hiding list to sfxpat
7594 let g:netrw_list_hide= sfxpat
7595 endif
7596 endfor
7597
7598 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007599 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007600" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7601 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007603 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007604 endif
7605
7606" call Dret("s:NetrwMarkHideSfx")
7607endfun
7608
7609" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007610" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007611" Uses the local marked-file list.
7612fun! s:NetrwMarkFileVimCmd(islocal)
7613" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007614 let svpos = winsaveview()
7615" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007616 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007617 let curbufnr = bufnr("%")
7618
Bram Moolenaarff034192013-04-24 18:51:19 +02007619 " sanity check
7620 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007621 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007622" call Dret("s:NetrwMarkFileVimCmd")
7623 return
7624 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007625" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007626
Bram Moolenaar15146672011-10-20 22:22:38 +02007627 if exists("s:netrwmarkfilelist_{curbufnr}")
7628 " get the command
7629 call inputsave()
7630 let cmd= input("Enter vim command: ","","file")
7631 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007633 if cmd == ""
7634" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7635 return
7636 endif
7637
7638 " apply command to marked files. Substitute: filename -> %
7639 " If no %, then append a space and the filename to the command
7640 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007642 if a:islocal
7643 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007644 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007645" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007646 exe cmd
7647 exe "sil! keepalt wq!"
7648 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007649" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007650 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007651 endif
7652 endfor
7653
7654 " unmark marked file list
7655 call s:NetrwUnmarkList(curbufnr,curdir)
7656
7657 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007658 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007659" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7660 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007662 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664
Bram Moolenaar15146672011-10-20 22:22:38 +02007665" call Dret("s:NetrwMarkFileVimCmd")
7666endfun
7667
7668" ---------------------------------------------------------------------
7669" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7670" as the marked file(s) (toggles suffix presence)
7671" Uses the local marked file list.
7672fun! s:NetrwMarkHideSfx(islocal)
7673" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007674 let svpos = winsaveview()
7675" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007676 let curbufnr = bufnr("%")
7677
7678 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7679 if exists("s:netrwmarkfilelist_{curbufnr}")
7680
7681 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007682" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007683 " construct suffix pattern
7684 if fname =~ '\.'
7685 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7686 else
7687 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7688 endif
7689 " determine if its in the hiding list or not
7690 let inhidelist= 0
7691 if g:netrw_list_hide != ""
7692 let itemnum = 0
7693 let hidelist= split(g:netrw_list_hide,',')
7694 for hidepat in hidelist
7695 if sfxpat == hidepat
7696 let inhidelist= 1
7697 break
7698 endif
7699 let itemnum= itemnum + 1
7700 endfor
7701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007702" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007703 if inhidelist
7704 " remove sfxpat from list
7705 call remove(hidelist,itemnum)
7706 let g:netrw_list_hide= join(hidelist,",")
7707 elseif g:netrw_list_hide != ""
7708 " append sfxpat to non-empty list
7709 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7710 else
7711 " set hiding list to sfxpat
7712 let g:netrw_list_hide= sfxpat
7713 endif
7714 endfor
7715
7716 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007717 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007718" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7719 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007720 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007721 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007722 endif
7723
7724" call Dret("s:NetrwMarkHideSfx")
7725endfun
7726
7727" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007728" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7729" Uses the global markfilelist
7730fun! s:NetrwMarkFileGrep(islocal)
7731" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007732 let svpos = winsaveview()
7733" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007734 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007736
7737 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007738" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007739 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007740" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007742 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007743" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007744 let netrwmarkfilelist= "*"
7745 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007748" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007749 call inputsave()
7750 let pat= input("Enter pattern: ","")
7751 call inputrestore()
7752 let patbang = ""
7753 if pat =~ '^!'
7754 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007756 endif
7757 if pat =~ '^\i'
7758 let pat = escape(pat,'/')
7759 let pat = '/'.pat.'/'
7760 else
7761 let nonisi = pat[0]
7762 endif
7763
7764 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007766 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007767 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007768 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007769 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007770" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7771 return
7772 endtry
7773 echo "(use :cn, :cp to navigate, :Rex to return)"
7774
7775 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007776" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7777 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007778
7779 if exists("nonisi")
7780 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007781" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007782 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007783 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007785 endif
7786
7787" call Dret("s:NetrwMarkFileGrep")
7788endfun
7789
7790" ---------------------------------------------------------------------
7791" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7792" uses the global marked file list
7793" s:netrwmfloc= 0: target directory is remote
7794" = 1: target directory is local
7795fun! s:NetrwMarkFileMove(islocal)
7796" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798 let curbufnr = bufnr("%")
7799
7800 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007801 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007802 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803" call Dret("s:NetrwMarkFileMove")
7804 return
7805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007807
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007809 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007810" call Dret("s:NetrwMarkFileCopy 0")
7811 return 0
7812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007813" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814
7815 if a:islocal && s:netrwmftgt_islocal
7816 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007817" call Decho("move from local to local",'~'.expand("<slnum>"))
7818" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007819 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007820 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7821" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7822 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007824 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007826 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007829 if g:netrw_localmovecmd =~ '\s'
7830 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7831 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7832 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007834 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007835 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 endif
7838 else
7839 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007840" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007841 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007842 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007843 if g:netrw_keepdir
7844 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7845 let fname= b:netrw_curdir."/".fname
7846 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007847 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007848 let fname= substitute(fname,'/','\\','g')
7849 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007851 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007852 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 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 +01007855 else
7856 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7857 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007858 break
7859 endif
7860 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861
7862 elseif a:islocal && !s:netrwmftgt_islocal
7863 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("move from local to remote",'~'.expand("<slnum>"))
7865" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007867 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 for fname in mflist
7870 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7871 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7872 endfor
7873 unlet mflist
7874
7875 elseif !a:islocal && s:netrwmftgt_islocal
7876 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("move from remote to local",'~'.expand("<slnum>"))
7878" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007880 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007881" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 for fname in mflist
7883 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7884 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7885 endfor
7886 unlet mflist
7887
7888 elseif !a:islocal && !s:netrwmftgt_islocal
7889 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7891" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 for fname in mflist
7896 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7897 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7898 endfor
7899 unlet mflist
7900 endif
7901
7902 " -------
7903 " cleanup
7904 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007905" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906
7907 " remove markings from local buffer
7908 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7909
7910 " refresh buffers
7911 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007912" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007913 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914 endif
7915 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007916" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007917 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007919 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007921 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924" call Dret("s:NetrwMarkFileMove")
7925endfun
7926
7927" ---------------------------------------------------------------------
7928" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7929" using the hardcopy command. Local marked-file list only.
7930fun! s:NetrwMarkFilePrint(islocal)
7931" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7932 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007933
7934 " sanity check
7935 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007936 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007937" call Dret("s:NetrwMarkFilePrint")
7938 return
7939 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007940" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7941 let curdir= s:NetrwGetCurdir(a:islocal)
7942
Bram Moolenaar446cb832008-06-24 21:56:24 +00007943 if exists("s:netrwmarkfilelist_{curbufnr}")
7944 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007945 call s:NetrwUnmarkList(curbufnr,curdir)
7946 for fname in netrwmarkfilelist
7947 if a:islocal
7948 if g:netrw_keepdir
7949 let fname= s:ComposePath(curdir,fname)
7950 endif
7951 else
7952 let fname= curdir.fname
7953 endif
7954 1split
7955 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007957 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007958" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 hardcopy
7960 q
7961 endfor
7962 2match none
7963 endif
7964" call Dret("s:NetrwMarkFilePrint")
7965endfun
7966
7967" ---------------------------------------------------------------------
7968" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7969" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007970" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007971fun! s:NetrwMarkFileRegexp(islocal)
7972" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7973
7974 " get the regular expression
7975 call inputsave()
7976 let regexp= input("Enter regexp: ","","file")
7977 call inputrestore()
7978
7979 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007980 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007981" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007982 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007984 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007985 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007986 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007987 else
7988 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007991" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992
7993 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007994 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007995 if fname =~ '^'.fnameescape(curdir)
7996" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7997 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7998 else
7999" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8001 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008002 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008003
8004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008005" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 " convert displayed listing into a filelist
8008 let eikeep = &ei
8009 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008010 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008011 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008012" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008014 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008015 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008016 sil NetrwKeepj norm! "ap
8017 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008020 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008023 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8029 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008030 call histdel("/",-1)
8031 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 endif
8033 " convert regexp into the more usual glob-style format
8034 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008037 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 let filelist= getline(1,line("$"))
8039 q!
8040 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008041 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 endfor
8043 unlet filelist
8044 let @a = areg
8045 let &ei = eikeep
8046 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008047 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048
8049" call Dret("s:NetrwMarkFileRegexp")
8050endfun
8051
8052" ---------------------------------------------------------------------
8053" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8054" Uses the local marked file list.
8055fun! s:NetrwMarkFileSource(islocal)
8056" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8057 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008058
8059 " sanity check
8060 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008062" call Dret("s:NetrwMarkFileSource")
8063 return
8064 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8066 let curdir= s:NetrwGetCurdir(a:islocal)
8067
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 if exists("s:netrwmarkfilelist_{curbufnr}")
8069 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 call s:NetrwUnmarkList(curbufnr,curdir)
8071 for fname in netrwmarkfilelist
8072 if a:islocal
8073 if g:netrw_keepdir
8074 let fname= s:ComposePath(curdir,fname)
8075 endif
8076 else
8077 let fname= curdir.fname
8078 endif
8079 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008080" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008081 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 endfor
8083 2match none
8084 endif
8085" call Dret("s:NetrwMarkFileSource")
8086endfun
8087
8088" ---------------------------------------------------------------------
8089" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8090" Uses the global markfilelist
8091fun! s:NetrwMarkFileTag(islocal)
8092" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008093 let svpos = winsaveview()
8094" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096 let curbufnr = bufnr("%")
8097
Bram Moolenaarff034192013-04-24 18:51:19 +02008098 " sanity check
8099 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008100 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008101" call Dret("s:NetrwMarkFileTag")
8102 return
8103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008104" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008105
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8108 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 call s:NetrwUnmarkAll()
8110
8111 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008112
8113" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8114 call system(g:netrw_ctags." ".netrwmarkfilelist)
8115 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8117 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008118
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008120 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008121 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 let curdir= b:netrw_curdir
8123 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008124 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008128 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 wq!
8130 endif
8131 2match none
8132 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008133" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8134 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 endif
8136
8137" call Dret("s:NetrwMarkFileTag")
8138endfun
8139
8140" ---------------------------------------------------------------------
8141" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008143" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008144" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008145" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008147" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8148 let svpos = winsaveview()
8149" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 let hadtgt = exists("s:netrwmftgt")
8152 if !exists("w:netrw_bannercnt")
8153 let w:netrw_bannercnt= b:netrw_bannercnt
8154 endif
8155
8156 " set up target
8157 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008159 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8160 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 unlet s:netrwmftgt s:netrwmftgt_islocal
8163 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008164 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 endif
8166 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008167" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8168 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008169" call Dret("s:NetrwMarkFileTgt : removed target")
8170 return
8171 else
8172 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008173" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008174 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175
8176 else
8177 " get word under cursor.
8178 " * If directory, use it for the target.
8179 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 let curword= s:NetrwGetWord()
8182 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 elseif !a:islocal && tgtdir =~ '/$'
8187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 else
8190 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 endif
8193 endif
8194 if a:islocal
8195 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8196 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 endif
8199 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8202 endif
8203 let s:netrwmftgt_islocal= a:islocal
8204
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205 " need to do refresh so that the banner will be updated
8206 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008207 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008208" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008209 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008212 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8214 else
8215 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8216 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008217" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8218 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008220 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008221 endif
8222
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8224" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8226endfun
8227
8228" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8230fun! s:NetrwGetCurdir(islocal)
8231" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8232
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008233 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008234 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8235" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8236 elseif !exists("b:netrw_curdir")
8237 let b:netrw_curdir= getcwd()
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8239 endif
8240
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008241" 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 +01008242 if b:netrw_curdir !~ '\<\a\{3,}://'
8243 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245 if g:netrw_keepdir == 0
8246 call s:NetrwLcd(curdir)
8247 endif
8248 endif
8249
8250" call Dret("s:NetrwGetCurdir <".curdir.">")
8251 return b:netrw_curdir
8252endfun
8253
8254" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008255" s:NetrwOpenFile: query user for a filename and open it {{{2
8256fun! s:NetrwOpenFile(islocal)
8257" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008258 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008259 call inputsave()
8260 let fname= input("Enter filename: ")
8261 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008262" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8263
8264 " determine if Lexplore is in use
8265 if exists("t:netrw_lexbufnr")
8266 " check if t:netrw_lexbufnr refers to a netrw window
8267" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8268 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8269 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8270" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8271 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8272 exe "NetrwKeepj e ".fnameescape(fname)
8273 let @@= ykeep
8274" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8275 endif
8276 endif
8277
8278 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008279 if fname !~ '[/\\]'
8280 if exists("b:netrw_curdir")
8281 if exists("g:netrw_quiet")
8282 let netrw_quiet_keep = g:netrw_quiet
8283 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008284 let g:netrw_quiet = 1
8285 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008286 let s:rexposn_{bufnr("%")}= winsaveview()
8287" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008288 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008289 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008290 else
8291 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8292 endif
8293 if exists("netrw_quiet_keep")
8294 let g:netrw_quiet= netrw_quiet_keep
8295 else
8296 unlet g:netrw_quiet
8297 endif
8298 endif
8299 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008300 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008301 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008302 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008303" call Dret("s:NetrwOpenFile")
8304endfun
8305
8306" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008307" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8308" For the mapping to this function be made via
8309" netrwPlugin, you'll need to have had
8310" g:netrw_usetab set to non-zero.
8311fun! netrw#Shrink()
8312" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8313 let curwin = winnr()
8314 let wiwkeep = &wiw
8315 set wiw=1
8316
8317 if &ft == "netrw"
8318 if winwidth(0) > g:netrw_wiw
8319 let t:netrw_winwidth= winwidth(0)
8320 exe "vert resize ".g:netrw_wiw
8321 wincmd l
8322 if winnr() == curwin
8323 wincmd h
8324 endif
8325" call Decho("vert resize 0",'~'.expand("<slnum>"))
8326 else
8327 exe "vert resize ".t:netrw_winwidth
8328" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8329 endif
8330
8331 elseif exists("t:netrw_lexbufnr")
8332 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8333 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8334 let t:netrw_winwidth= winwidth(0)
8335 exe "vert resize ".g:netrw_wiw
8336 wincmd l
8337 if winnr() == curwin
8338 wincmd h
8339 endif
8340" call Decho("vert resize 0",'~'.expand("<slnum>"))
8341 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8342 exe "vert resize ".t:netrw_winwidth
8343" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8344 else
8345 call netrw#Lexplore(0,0)
8346 endif
8347
8348 else
8349 call netrw#Lexplore(0,0)
8350 endif
8351 let wiw= wiwkeep
8352
8353" call Dret("netrw#Shrink")
8354endfun
8355
8356" ---------------------------------------------------------------------
8357" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8358fun! s:NetSortSequence(islocal)
8359" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8360
8361 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008362 let svpos= winsaveview()
8363" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364 call inputsave()
8365 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8366 call inputrestore()
8367
8368 " refresh the listing
8369 let g:netrw_sort_sequence= newsortseq
8370 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8372 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008373 let @@= ykeep
8374
8375" call Dret("NetSortSequence")
8376endfun
8377
8378" ---------------------------------------------------------------------
8379" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8380" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008381" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382fun! s:NetrwUnmarkList(curbufnr,curdir)
8383" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8384
8385 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008386 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8388 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8389 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8390 call remove(s:netrwmarkfilelist,idx) " remove from global list
8391 endfor
8392 if s:netrwmarkfilelist == []
8393 unlet s:netrwmarkfilelist
8394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395
Bram Moolenaar446cb832008-06-24 21:56:24 +00008396 " getting rid of the local marked-file lists is easy
8397 unlet s:netrwmarkfilelist_{a:curbufnr}
8398 endif
8399 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8400 unlet s:netrwmarkfilemtch_{a:curbufnr}
8401 endif
8402 2match none
8403" call Dret("s:NetrwUnmarkList")
8404endfun
8405
8406" ---------------------------------------------------------------------
8407" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8408fun! s:NetrwUnmarkAll()
8409" call Dfunc("s:NetrwUnmarkAll()")
8410 if exists("s:netrwmarkfilelist")
8411 unlet s:netrwmarkfilelist
8412 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008413 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414 2match none
8415" call Dret("s:NetrwUnmarkAll")
8416endfun
8417
8418" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008419" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420fun! s:NetrwUnmarkAll2()
8421" call Dfunc("s:NetrwUnmarkAll2()")
8422 redir => netrwmarkfilelist_let
8423 let
8424 redir END
8425 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008426 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8428 for flist in netrwmarkfilelist_list
8429 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8430 unlet s:netrwmarkfilelist_{curbufnr}
8431 unlet s:netrwmarkfilemtch_{curbufnr}
8432 endfor
8433" call Dret("s:NetrwUnmarkAll2")
8434endfun
8435
8436" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008437" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8438"
8439" Marked files are in two types of lists:
8440" s:netrwmarkfilelist -- holds complete paths to all marked files
8441" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8442"
8443" Marked files suitable for use with 2match are in:
8444" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445fun! s:NetrwUnMarkFile(islocal)
8446" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008447 let svpos = winsaveview()
8448" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 let curbufnr = bufnr("%")
8450
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008451 " unmark marked file list
8452 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8453 if exists("s:netrwmarkfilelist")
8454" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456 endif
8457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008458 let ibuf= 1
8459 while ibuf < bufnr("$")
8460 if exists("s:netrwmarkfilelist_".ibuf)
8461 unlet s:netrwmarkfilelist_{ibuf}
8462 unlet s:netrwmarkfilemtch_{ibuf}
8463 endif
8464 let ibuf = ibuf + 1
8465 endwhile
8466 2match none
8467
Bram Moolenaar446cb832008-06-24 21:56:24 +00008468" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008469"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8470call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call Dret("s:NetrwUnMarkFile")
8472endfun
8473
8474" ---------------------------------------------------------------------
8475" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8476fun! s:NetrwMenu(domenu)
8477
8478 if !exists("g:NetrwMenuPriority")
8479 let g:NetrwMenuPriority= 80
8480 endif
8481
Bram Moolenaaradc21822011-04-01 18:03:16 +02008482 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008483" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8484
8485 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008486" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008487 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008488 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8492 if g:netrw_dirhistmax > 0
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8497 else
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8499 endif
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8514 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 +01008515 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 +02008516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8545 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>'
8546 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>'
8547 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>'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8549 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>'
8550 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>'
8551 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 +01008552 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 +02008553 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008556 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8557 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558
8559 elseif !a:domenu
8560 let s:netrwcnt = 0
8561 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008562 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563 exe curwin."wincmd w"
8564
8565 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008566" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008567 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008568" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008569 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008570 endif
8571 endif
8572" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008573 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574 endif
8575
8576endfun
8577
8578" ---------------------------------------------------------------------
8579" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8580" Used by the O maps (as <SID>NetrwObtain())
8581fun! s:NetrwObtain(islocal)
8582" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8583
Bram Moolenaar97d62492012-11-15 21:28:22 +01008584 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008587 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8589 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008590 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008592 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593
8594" call Dret("NetrwObtain")
8595endfun
8596
8597" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8599" If there's only one window, then the window will first be split.
8600" Returns:
8601" choice = 0 : didn't have to choose
8602" choice = 1 : saved modified file in window first
8603" choice = 2 : didn't save modified file, opened window
8604" choice = 3 : cancel open
8605fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008606" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
Bram Moolenaar97d62492012-11-15 21:28:22 +01008608 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008610 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008611" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612
8613 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008614 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008616" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8617" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8618 let curword = s:NetrwGetWord()
8619 let choice = 0
8620 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8621" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008622 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008623" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008624 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008625" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008627" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628
Bram Moolenaar8d043172014-01-23 14:24:41 +01008629 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 if lastwinnr == 1
8631 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008632" 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 +02008633 " g:netrw_preview=0: preview window shown in a horizontally split window
8634 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008636 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008637 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008638" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008639 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008641 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008642 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008643" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008644 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008646 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008647" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648
8649 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008650" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008651 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008653 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008654" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008655 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008656" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008658" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008659" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008660" call Decho("COMBAK#12: mod=".&mod)
8661
8662 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8663 " whoops -- user trying to open file in the Lexplore window.
8664 " Use Lexplore's opening-file window instead.
8665" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8666" exe g:netrw_chgwin."wincmd w"
8667 wincmd p
8668 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8669 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670
8671 " prevwinnr: the window number of the "prev" window
8672 " prevbufnr: the buffer number of the buffer in the "prev" window
8673 " bnrcnt : the qty of windows open on the "prev" buffer
8674 let prevwinnr = winnr()
8675 let prevbufnr = bufnr("%")
8676 let prevbufname = bufname("%")
8677 let prevmod = &mod
8678 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008679" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008680 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008681" 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 +01008682" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683
8684 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685 " and it doesn't appear in any other extant window, then ask the
8686 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008687 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008691 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008693
8694 if bnrcnt == 1 && &hidden == 0
8695 " only one copy of the modified buffer in a window, and
8696 " hidden not set, so overwriting will lose the modified file. Ask first...
8697 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008698" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008700" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if choice == 1
8703 " Yes -- write file & then browse
8704 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008705 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008707 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008708 exe origwin."wincmd w"
8709 let &ei = eikeep
8710 let @@ = ykeep
8711" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 return choice
8713 endif
8714
8715 elseif choice == 2
8716 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008717" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008718 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719
8720 else
8721 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 exe origwin."wincmd w"
8724 let &ei= eikeep
8725 let @@ = ykeep
8726" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008727 return choice
8728 endif
8729 endif
8730 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008731 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008732 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008733" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734
8735 " restore b:netrw_curdir (window split/enew may have lost it)
8736 let b:netrw_curdir= curdir
8737 if a:islocal < 2
8738 if a:islocal
8739 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8740 else
8741 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8742 endif
8743 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008744 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008745" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008746 return choice
8747endfun
8748
8749" ---------------------------------------------------------------------
8750" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8751" Always assumed to be local -> remote
8752" call s:NetrwUpload(filename, target)
8753" call s:NetrwUpload(filename, target, fromdirectory)
8754fun! s:NetrwUpload(fname,tgt,...)
8755" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8756
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008757 if a:tgt =~ '^\a\{3,}://'
8758 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759 else
8760 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8761 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763
8764 if a:0 > 0
8765 let fromdir= a:1
8766 else
8767 let fromdir= getcwd()
8768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
8771 if type(a:fname) == 1
8772 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008773" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8776 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8777" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 if a:tgt =~ '/$'
8779 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008780" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008781 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008782 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008784 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 endif
8787 q!
8788
8789 elseif type(a:fname) == 3
8790 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008791" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 let curdir= getcwd()
8793 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008794 if s:NetrwLcd(fromdir)
8795" call Dret("s:NetrwUpload : lcd failure")
8796 return
8797 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008798 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 if exists("g:netrw_port") && g:netrw_port != ""
8801 let useport= " ".g:netrw_scpport." ".g:netrw_port
8802 else
8803 let useport= ""
8804 endif
8805 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8806 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807 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 +02008808 if s:NetrwLcd(curdir)
8809" call Dret("s:NetrwUpload : lcd failure")
8810 return
8811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812
8813 elseif a:tgt =~ '^ftp:'
8814 call s:NetrwMethod(a:tgt)
8815
8816 if b:netrw_method == 2
8817 " handle uploading a list of files via ftp+.netrc
8818 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008819 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
8825 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828 endif
8829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832
Bram Moolenaaradc21822011-04-01 18:03:16 +02008833 if tgtdir == ""
8834 let tgtdir= '/'
8835 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838
8839 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endfor
8843
8844 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008845 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 +00008846 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8848 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 endif
8850 " 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 +01008851 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008852 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8854 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8855 else
8856 bw!|q
8857 endif
8858
8859 elseif b:netrw_method == 3
8860 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8861 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008864 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865
8866 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008867 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008868" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008869 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 endif
8873
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008874 if exists("g:netrw_uid") && g:netrw_uid != ""
8875 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008876 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008878 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008882 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 endif
8887
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008888 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008890
8891 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008893" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 endif
8895
8896 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 endif
8900
8901 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 endfor
8905
8906 " perform ftp:
8907 " -i : turns off interactive prompting from ftp
8908 " -n unix : DON'T use <.netrc>, even though it exists
8909 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008910 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 " 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 +01008913 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008914 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8916 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008917 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8919 let &debug = debugkeep
8920 let mod = 1
8921 else
8922 bw!|q
8923 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008924 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008925" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008926 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 endif
8928 else
8929 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8930 endif
8931 endif
8932
8933" call Dret("s:NetrwUpload")
8934endfun
8935
8936" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008937" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008938fun! s:NetrwPreview(path) range
8939" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8941" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008942 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943 NetrwKeepj call s:NetrwOptionsSave("s:")
8944 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8945 NetrwKeepj call s:NetrwOptionsSafe(1)
8946 else
8947 NetrwKeepj call s:NetrwOptionsSafe(0)
8948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008951 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008952" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8953 if g:netrw_preview
8954 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008955 let pvhkeep = &pvh
8956 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8957 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008958" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8959 else
8960 " horizontal split
8961 let pvhkeep = &pvh
8962 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8963 let &pvh = winheight(0) - winsz
8964" 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 +02008965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008966 " g:netrw_preview g:netrw_alto
8967 " 1 : vert 1: top -- preview window is vertically split off and on the left
8968 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8969 " 0 : 1: top -- preview window is horizontally split off and on the top
8970 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8971 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008972 " 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 +02008973 " the BufEnter event set up in netrwPlugin.vim
8974" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8975 let eikeep = &ei
8976 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008977 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008978 let &ei= eikeep
8979" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 if exists("pvhkeep")
8981 let &pvh= pvhkeep
8982 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008984 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008985 endif
8986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 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 +00008988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008989 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008990 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991" call Dret("NetrwPreview")
8992endfun
8993
8994" ---------------------------------------------------------------------
8995" s:NetrwRefresh: {{{2
8996fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997" 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 +00008998 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008999 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("setl ma noro",'~'.expand("<slnum>"))
9001" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009002 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009003 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9004 if !exists("w:netrw_treetop")
9005 if exists("b:netrw_curdir")
9006 let w:netrw_treetop= b:netrw_curdir
9007 else
9008 let w:netrw_treetop= getcwd()
9009 endif
9010 endif
9011 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9012 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009013
9014 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009015 let screenposn = winsaveview()
9016" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009017
9018" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9019" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9020 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009022 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009024 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009025 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009026
9027 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009028" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9029 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009030
9031 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009032 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9033 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9034" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9035 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9036 else
9037" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9038 2match none
9039 endif
9040 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041
Bram Moolenaar97d62492012-11-15 21:28:22 +01009042" restore
9043 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009044" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045endfun
9046
9047" ---------------------------------------------------------------------
9048" s:NetrwRefreshDir: refreshes a directory by name {{{2
9049" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009050" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009052" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053 if g:netrw_fastbrowse == 0
9054 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009055" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009057" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058
9059 if tgtwin > 0
9060 " tgtwin is being displayed, so refresh it
9061 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009062" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 exe curwin."wincmd w"
9066
9067 elseif bufnr(a:dirname) > 0
9068 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009069" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9070 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 endif
9072
9073 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009074" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009075 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
9077" call Dret("s:NetrwRefreshDir")
9078endfun
9079
9080" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009081" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9082" window number to do its editing in.
9083" Supports [count]C where the count, if present, is used to specify
9084" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009086" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 if a:1 == "" " :NetrwC win#
9090 let g:netrw_chgwin= winnr()
9091 else " :NetrwC
9092 let g:netrw_chgwin= a:1
9093 endif
9094 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009095 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009096 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009097 let g:netrw_chgwin= winnr()
9098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009099 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009100" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009101endfun
9102
9103" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009104" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9105" What this function does is to compute a priority for the patterns
9106" in the g:netrw_sort_sequence. It applies a substitute to any
9107" "files" that satisfy each pattern, putting the priority / in
9108" front. An "*" pattern handles the default priority.
9109fun! s:NetrwSetSort()
9110" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009111 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 if w:netrw_liststyle == s:LONGLIST
9113 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9114 else
9115 let seqlist = g:netrw_sort_sequence
9116 endif
9117 " sanity check -- insure that * appears somewhere
9118 if seqlist == ""
9119 let seqlist= '*'
9120 elseif seqlist !~ '\*'
9121 let seqlist= seqlist.',*'
9122 endif
9123 let priority = 1
9124 while seqlist != ""
9125 if seqlist =~ ','
9126 let seq = substitute(seqlist,',.*$','','e')
9127 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9128 else
9129 let seq = seqlist
9130 let seqlist = ""
9131 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009132 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009133 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009135 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009137 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009139" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140
9141 " sanity check
9142 if w:netrw_bannercnt > line("$")
9143 " apparently no files were left after a Hiding pattern was used
9144" call Dret("SetSort : no files left after hiding")
9145 return
9146 endif
9147 if seq == '*'
9148 let starpriority= spriority
9149 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009150 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009151 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 " sometimes multiple sorting patterns will match the same file or directory.
9153 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009154 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9155 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009156 endif
9157 let priority = priority + 1
9158 endwhile
9159 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009160 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9161 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 endif
9163
9164 " Following line associated with priority -- items that satisfy a priority
9165 " pattern get prefixed by ###/ which permits easy sorting by priority.
9166 " Sometimes files can satisfy multiple priority patterns -- only the latest
9167 " priority pattern needs to be retained. So, at this point, these excess
9168 " priority prefixes need to be removed, but not directories that happen to
9169 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009170 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9171 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009172 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009173
9174" call Dret("SetSort")
9175endfun
9176
Bram Moolenaarff034192013-04-24 18:51:19 +02009177" ---------------------------------------------------------------------
9178" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9179" Implements [count]Tb (bookhist<b>)
9180" [count]Th (bookhist<h>)
9181" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009182fun! s:NetrwSetTgt(islocal,bookhist,choice)
9183" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009184
9185 if a:bookhist == 'b'
9186 " supports choosing a bookmark as a target using a qb-generated list
9187 let choice= a:choice - 1
9188 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009189 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009190 else
9191 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9192 endif
9193
9194 elseif a:bookhist == 'h'
9195 " supports choosing a history stack entry as a target using a qb-generated list
9196 let choice= (a:choice % g:netrw_dirhistmax) + 1
9197 if exists("g:netrw_dirhist_".choice)
9198 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009199 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009200 else
9201 echomsg "Sorry, history#".a:choice." not available!"
9202 endif
9203 endif
9204
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009205 " refresh the display
9206 if !exists("b:netrw_curdir")
9207 let b:netrw_curdir= getcwd()
9208 endif
9209 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9210
Bram Moolenaarff034192013-04-24 18:51:19 +02009211" call Dret("s:NetrwSetTgt")
9212endfun
9213
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009215" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009216fun! s:NetrwSortStyle(islocal)
9217" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009218 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009219 let svpos= winsaveview()
9220" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009222 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 +01009223 NetrwKeepj norm! 0
9224 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009225" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9226 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227
9228" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9229endfun
9230
9231" ---------------------------------------------------------------------
9232" s:NetrwSplit: mode {{{2
9233" =0 : net and o
9234" =1 : net and t
9235" =2 : net and v
9236" =3 : local and o
9237" =4 : local and t
9238" =5 : local and v
9239fun! s:NetrwSplit(mode)
9240" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9241
Bram Moolenaar97d62492012-11-15 21:28:22 +01009242 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 call s:SaveWinVars()
9244
9245 if a:mode == 0
9246 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009247 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009248 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009249" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009250 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009252 NetrwKeepj call s:RestoreWinVars()
9253 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 unlet s:didsplit
9255
9256 elseif a:mode == 1
9257 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009258 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 tabnew
9261 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj call s:RestoreWinVars()
9263 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 unlet s:didsplit
9265
9266 elseif a:mode == 2
9267 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009268 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009269 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009271 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009272 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009273 NetrwKeepj call s:RestoreWinVars()
9274 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 unlet s:didsplit
9276
9277 elseif a:mode == 3
9278 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009279 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009280 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009282 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009284 NetrwKeepj call s:RestoreWinVars()
9285 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 unlet s:didsplit
9287
9288 elseif a:mode == 4
9289 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009291 let eikeep = &ei
9292 let netrw_winnr = winnr()
9293 let netrw_line = line(".")
9294 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009295 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009296 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009297 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9299 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 let &ei = eikeep
9301 let netrw_curdir = s:NetrwTreeDir(0)
9302" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009303 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009304 let b:netrw_curdir = netrw_curdir
9305 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009306 NetrwKeepj call s:RestoreWinVars()
9307 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009308 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009309 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009310 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9311 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009312 let &ei= eikeep
9313 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 unlet s:didsplit
9315
9316 elseif a:mode == 5
9317 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009318 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009319 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009321 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009323 NetrwKeepj call s:RestoreWinVars()
9324 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 unlet s:didsplit
9326
9327 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009328 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009329 endif
9330
Bram Moolenaar97d62492012-11-15 21:28:22 +01009331 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332" call Dret("s:NetrwSplit")
9333endfun
9334
9335" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009336" s:NetrwTgtMenu: {{{2
9337fun! s:NetrwTgtMenu()
9338 if !exists("s:netrw_menucnt")
9339 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009340 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009341" call Dfunc("s:NetrwTgtMenu()")
9342
9343 " the following test assures that gvim is running, has menus available, and has menus enabled.
9344 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9345 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009346" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009347 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9348 endif
9349 if !exists("s:netrw_initbookhist")
9350 call s:NetrwBookHistRead()
9351 endif
9352
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353 " try to cull duplicate entries
9354 let tgtdict={}
9355
Bram Moolenaarff034192013-04-24 18:51:19 +02009356 " target bookmarked places
9357 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009358" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 let cnt= 1
9360 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361 if has_key(tgtdict,bmd)
9362 let cnt= cnt + 1
9363 continue
9364 endif
9365 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009366 let ebmd= escape(bmd,g:netrw_menu_escape)
9367 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009369 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 +02009370 let cnt= cnt + 1
9371 endfor
9372 endif
9373
9374 " target directory browsing history
9375 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009377 let histcnt = 1
9378 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009379 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 if exists("g:netrw_dirhist_{histcnt}")
9381 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382 if has_key(tgtdict,histentry)
9383 let histcnt = histcnt + 1
9384 continue
9385 endif
9386 let tgtdict[histentry] = histcnt
9387 let ehistentry = escape(histentry,g:netrw_menu_escape)
9388" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009389 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 +02009390 endif
9391 let histcnt = histcnt + 1
9392 endwhile
9393 endif
9394 endif
9395" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009396endfun
9397
9398" ---------------------------------------------------------------------
9399" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9400" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009401fun! s:NetrwTreeDir(islocal)
9402" 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 +02009403" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009404" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9405" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9406" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009407" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009409 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009410 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009411" 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 +01009412 let treedir= s:treedir
9413 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414 unlet s:prevwinopen
9415" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009416 return treedir
9417 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009418 if exists("s:prevwinopen")
9419 unlet s:prevwinopen
9420 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009421" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422
Bram Moolenaar8d043172014-01-23 14:24:41 +01009423 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9424 let b:netrw_curdir= getcwd()
9425 endif
9426 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009428" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009429
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009430 let s:treecurpos= winsaveview()
9431" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009432" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433
9434 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9436" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009438
9439 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009440 let curline= substitute(getline('.'),"\t -->.*$",'','')
9441 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009443 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9445 elseif curline =~ '@$'
9446" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009447 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009450" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009451 let treedir= ""
9452 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009453" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454
9455 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9457" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009458" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009459 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009462" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9463 sil! NetrwKeepj %d _
9464" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009465 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009466" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009467" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009469" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009472" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009473" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009474
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009475 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9476" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9477" let newdir = w:netrw_treetop.'/'.potentialdir
9478" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9479" let treedir = s:NetrwTreePath(newdir)
9480" let w:netrw_treetop = newdir
9481" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9482" else
9483" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009484 if a:islocal && curline =~ '@$'
9485 if isdirectory(s:NetrwFile(potentialdir))
9486 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9487 let w:netrw_treetop = treedir
9488 endif
9489 else
9490 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9491 let treedir = s:NetrwTreePath(w:netrw_treetop)
9492 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009493 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009494" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009495
9496 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009497 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009499" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009502 return treedir
9503endfun
9504
9505" ---------------------------------------------------------------------
9506" s:NetrwTreeDisplay: recursive tree display {{{2
9507fun! s:NetrwTreeDisplay(dir,depth)
9508" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9509
9510 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009511 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009512
9513 " install ../ and shortdir
9514 if a:depth == ""
9515 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009518 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519 if a:dir == w:netrw_treetop
9520 let shortdir= a:dir
9521 else
9522 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9523 endif
9524 call setline(line("$")+1,a:depth.shortdir)
9525 else
9526 let shortdir= substitute(a:dir,'^.*/','','e')
9527 call setline(line("$")+1,a:depth.shortdir.'/')
9528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009529" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530 " append a / to dir if its missing one
9531 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009532
9533 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009534 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
Bram Moolenaar85850f32019-07-19 22:05:51 +02009537 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9538 if g:netrw_hide == 1
9539 " hide given patterns
9540 let listhide= split(g:netrw_list_hide,',')
9541" call Decho("listhide=".string(listhide))
9542 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009543 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009544 endfor
9545
9546 elseif g:netrw_hide == 2
9547 " show given patterns (only)
9548 let listhide= split(g:netrw_list_hide,',')
9549" call Decho("listhide=".string(listhide))
9550 let entries=[]
9551 for entry in w:netrw_treedict[dir]
9552 for pat in listhide
9553 if entry =~ pat
9554 call add(entries,entry)
9555 break
9556 endif
9557 endfor
9558 endfor
9559 let w:netrw_treedict[dir]= entries
9560 endif
9561 if depth != ""
9562 " always remove "." and ".." entries when there's depth
9563 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9564 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9565 endif
9566
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009567" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009568 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009569 if dir =~ '/$'
9570 let direntry= substitute(dir.entry,'[@/]$','','e')
9571 else
9572 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9573 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009574" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009577 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9580 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9581 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009584 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 endif
9588 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009589" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009590
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591" call Dret("NetrwTreeDisplay")
9592endfun
9593
9594" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009595" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9596fun! s:NetrwRefreshTreeDict(dir)
9597" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009598 if !exists("w:netrw_treedict")
9599" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9600 return
9601 endif
9602
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603 for entry in w:netrw_treedict[a:dir]
9604 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9605" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9606
9607 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9608" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9609 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009610 let liststar = s:NetrwGlob(direntry,'*',1)
9611 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009612 let w:netrw_treedict[direntry] = liststar + listdotstar
9613" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9614
9615 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9616" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9617 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009618 let liststar = s:NetrwGlob(direntry.'/','*',1)
9619 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009620 let w:netrw_treedict[direntry]= liststar + listdotstar
9621" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9622
9623 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9624" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9625 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009626 let liststar = s:NetrwGlob(direntry.'/','*',1)
9627 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009628" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9629
9630 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009631" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009632 endif
9633 endfor
9634" call Dret("s:NetrwRefreshTreeDict")
9635endfun
9636
9637" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009639" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009641 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009642" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009643" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9644" 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>"))
9645" 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 +00009646
9647 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009649" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009651 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 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 +02009654" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009656 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 if exists("w:netrw_treetop")
9660 let s:netrw_treetop= w:netrw_treetop
9661 else
9662 let w:netrw_treetop= getcwd()
9663 let s:netrw_treetop= w:netrw_treetop
9664 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667 " insure that we have a treedict, albeit empty
9668" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 let w:netrw_treedict= {}
9670 endif
9671
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009672 " update the dictionary for the current directory
9673" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679
9680 " if past banner, record word
9681 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9682 let fname= expand("<cword>")
9683 else
9684 let fname= ""
9685 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9687" 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 +00009688
9689 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009690" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009691 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009692" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009693
9694 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9695 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009696" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009697 1d
9698 endwhile
9699
Bram Moolenaar13600302014-05-22 18:26:40 +02009700 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009702" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009703 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704 endif
9705endfun
9706
9707" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009708" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009709" Normally, treetop is w:netrw_treetop, but a
9710" user of the function ( netrw#SetTreetop() )
9711" wipes that out prior to calling this function
9712fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009713" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9714 if line(".") < w:netrw_bannercnt + 2
9715 let treedir= a:treetop
9716 if treedir !~ '/$'
9717 let treedir= treedir.'/'
9718 endif
9719" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9720 return treedir
9721 endif
9722
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009723 let svpos = winsaveview()
9724" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009725 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009726" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009727 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9729 let curline= getline('.')
9730" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9731 if curline =~ '/$'
9732" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9733 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9734" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9735 elseif curline =~ '@\s\+-->'
9736" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9737 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9738 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9739" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009740 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009742 let treedir= ""
9743 endif
9744 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9746" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009747 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9748 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9749 let treedir= dirname.treedir
9750 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009751" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009753" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 if a:treetop =~ '/$'
9755 let treedir= a:treetop.treedir
9756 else
9757 let treedir= a:treetop.'/'.treedir
9758 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009759" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009761" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009762" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9763 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009764" call Dret("s:NetrwTreePath <".treedir.">")
9765 return treedir
9766endfun
9767
9768" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009769" s:NetrwWideListing: {{{2
9770fun! s:NetrwWideListing()
9771
9772 if w:netrw_liststyle == s:WIDELIST
9773" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9774 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009775 " cpf: characters per filename
9776 " fpl: filenames per line
9777 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009778 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009779 let dict={}
9780 " save the unnamed register and register 0-9 and a
9781 let dict.a=[getreg('a'), getregtype('a')]
9782 for i in range(0, 9)
9783 let dict[i] = [getreg(i), getregtype(i)]
9784 endfor
9785 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009787 let b:netrw_cpf= 0
9788 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009789 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009790 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9791 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009792 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009793 " restore stored registers
9794 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795" call Dret("NetrwWideListing")
9796 return
9797 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009798 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009799 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801
9802 " determine qty files per line (fpl)
9803 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9804 if w:netrw_fpl <= 0
9805 let w:netrw_fpl= 1
9806 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009807" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808
9809 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810 " fpc: files per column of wide listing
9811 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009812 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9814 let newcolstart = w:netrw_bannercnt + fpc
9815 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009817 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009818" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009819 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009820 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009821 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 while line("$") >= newcolstart
9823 if newcolend > line("$") | let newcolend= line("$") | endif
9824 let newcolqty= newcolend - newcolstart
9825 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009826 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009828 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009829 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009830 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009831 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009832 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009833 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009835 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009836" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009837 if @* != keepregstar | sil! let @* = keepregstar | endif
9838 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009839 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009840 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9841 NetrwKeepj call histdel("/",-1)
9842 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9843 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009844" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009845 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009846 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009847" 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 +00009848" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009849 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009850 else
9851 if hasmapto("w","n")
9852 sil! nunmap <buffer> w
9853 endif
9854 if hasmapto("b","n")
9855 sil! nunmap <buffer> b
9856 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009858endfun
9859
9860" ---------------------------------------------------------------------
9861" s:PerformListing: {{{2
9862fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009863" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9864" 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 +02009865" 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>"))
9866 sil! NetrwKeepj %d _
9867" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868
Bram Moolenaar15146672011-10-20 22:22:38 +02009869 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009871 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009872
Bram Moolenaar85850f32019-07-19 22:05:51 +02009873 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009874 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876
9877" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009878" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879" endif " Decho
9880
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9883 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009884" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9885 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886 endif
9887
9888 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009890
9891 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009892 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895 if exists("g:netrw_pchk")
9896 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9897 " failure detections.
9898 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009899 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9901 endif
9902 if exists("g:netrw_pchk")
9903 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9904 else
9905 let curdir= b:netrw_curdir
9906 endif
9907 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9908 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9909 else
9910 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009911 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009912 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009913 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009914 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009916 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009917 let w:netrw_bannercnt= 1
9918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009919" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9920" 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 +00009921
Bram Moolenaar85850f32019-07-19 22:05:51 +02009922 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009923 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009924 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925 let sortby= sortby." reversed"
9926 endif
9927
9928 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009929 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009931 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009933 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009934 NetrwKeepj put ='\" Sorted by '.sortby
9935 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009936 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9937 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009939 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9942 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009943 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009944" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" 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 +00009946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947
Bram Moolenaar85850f32019-07-19 22:05:51 +02009948 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 if g:netrw_banner
9950 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009951" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009953 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009955 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009956 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009957 endif
9958 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009963 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964
9965 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009966 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009967" 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 +01009968 if g:netrw_list_hide != "" && g:netrw_hide
9969 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 endif
9974 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009976 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009977
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" 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 +01009979 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009981 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009982" 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 +01009983 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009985" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009986" 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 +00009987 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009988
9989 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009990 if g:netrw_banner
9991 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" 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 +01009994" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009995" 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 +01009996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010002 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010003 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010004 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010005" 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 +010010006" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10007 return
10008 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010
10011 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010012 if !exists("w:netrw_bannercnt")
10013 let w:netrw_bannercnt= 0
10014 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10016" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10017" 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 +010010018
Bram Moolenaar5c736222010-01-06 20:54:52 +010010019 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010020" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" 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 +000010022 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010023 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010025 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010028 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010030" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032
Bram Moolenaar5c736222010-01-06 20:54:52 +010010033 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010035 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010036 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010037 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 else
10039 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 endif
10042 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010043
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010046 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10047 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010049 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010050 " exten: sort by extension
10051 " The histdel(...,-1) calls remove the last search from the search history
10052" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010053 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10054 NetrwKeepj call histdel("/",-1)
10055 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10056 NetrwKeepj call histdel("/",-1)
10057 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10058 NetrwKeepj call histdel("/",-1)
10059 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10060" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010061 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062 " normal direction sorting
10063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10064 else
10065 " reverse direction sorting
10066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10067 endif
10068 endif
10069 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10070 NetrwKeepj call histdel("/",-1)
10071
Bram Moolenaar446cb832008-06-24 21:56:24 +000010072 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010073 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010074" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010075 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010078 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010082" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10084 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010085 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010086 endif
10087
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010088 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010089" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010090 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010091 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010092 call histdel("/",-1)
10093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010094 endif
10095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" 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 +000010097
10098 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10100" 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 +010010101 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" 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 +010010103 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104" 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 +000010105
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010106 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010107 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010109 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010110 endif
10111
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010113 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10115 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010116 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10118 else
10119" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10120" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10121" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10122" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010123 endif
10124
10125 " record previous current directory
10126 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010128
10129 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10131" 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 +010010132 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" 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 +020010134 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" 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 +000010136
10137 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010139 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010141 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010143 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10144 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010145" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010146" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010147
Bram Moolenaar8d043172014-01-23 14:24:41 +010010148 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10150" 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 +010010151" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10152 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010153 unlet s:treecurpos
10154 endif
10155
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" 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>"))
10157" 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 +000010158" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10159endfun
10160
10161" ---------------------------------------------------------------------
10162" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010163fun! s:SetupNetrwStatusLine(statline)
10164" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10165
10166 if !exists("s:netrw_setup_statline")
10167 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010169
10170 if !exists("s:netrw_users_stl")
10171 let s:netrw_users_stl= &stl
10172 endif
10173 if !exists("s:netrw_users_ls")
10174 let s:netrw_users_ls= &laststatus
10175 endif
10176
10177 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010178 let dict={}
10179 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010180 redir @a
10181 try
10182 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010183 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010184 if &bg == "dark"
10185 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10186 else
10187 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10188 endif
10189 endtry
10190 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010191 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010192 endif
10193
10194 " set up status line (may use User9 highlighting)
10195 " insure that windows have a statusline
10196 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010197 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010198 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010199" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010200 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010201
10202" call Dret("SetupNetrwStatusLine : stl=".&stl)
10203endfun
10204
Bram Moolenaar85850f32019-07-19 22:05:51 +020010205" =========================================
10206" Remote Directory Browsing Support: {{{1
10207" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010208
10209" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010210" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10211" This function assumes that a long listing will be received. Size, time,
10212" and reverse sorts will be requested of the server but not otherwise
10213" enforced here.
10214fun! s:NetrwRemoteFtpCmd(path,listcmd)
10215" 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 +010010216" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010217 " sanity check: {{{3
10218 if !exists("w:netrw_method")
10219 if exists("b:netrw_method")
10220 let w:netrw_method= b:netrw_method
10221 else
10222 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10223" call Dret("NetrwRemoteFtpCmd")
10224 return
10225 endif
10226 endif
10227
10228 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10229 let ffkeep= &ff
10230 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010231" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010232
10233 " clear off any older non-banner lines " {{{3
10234 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010235" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10236 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010237
10238 ".........................................
10239 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10240 " ftp + <.netrc>: Method #2
10241 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010242 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 endif
10244 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010247 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010248 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010250 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010251" 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>"))
10252 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 +010010253 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10255 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 +010010256 endif
10257
10258 ".........................................
10259 elseif w:netrw_method == 3 " {{{3
10260 " ftp + machine,id,passwd,filename: Method #3
10261 setl ff=unix
10262 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010263 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 endif
10267
10268 " handle userid and password
10269 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010270" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010271 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10272 call NetUserPass("ftp:".host)
10273 endif
10274 if exists("g:netrw_uid") && g:netrw_uid != ""
10275 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010277 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010278 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010279 endif
10280 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
10283 endif
10284
10285 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010286 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 endif
10288 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010290" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010293
10294 " perform ftp:
10295 " -i : turns off interactive prompting from ftp
10296 " -n unix : DON'T use <.netrc>, even though it exists
10297 " -n win32: quit being obnoxious about password
10298 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010299" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010300 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010301" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010302" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10303" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
10305
10306 ".........................................
10307 elseif w:netrw_method == 9 " {{{3
10308 " sftp username@machine: Method #9
10309 " s:netrw_sftp_cmd
10310 setl ff=unix
10311
10312 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010313 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010314" call Dret("NetrwRemoteFtpCmd")
10315 return
10316
10317 ".........................................
10318 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010319 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 endif
10321
10322 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010323 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010324 sil! NetrwKeepj %s/\r$//e
10325 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010326 endif
10327 if a:listcmd == "dir"
10328 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10330 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10331 NetrwKeepj call histdel("/",-1)
10332 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010333 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 +010010334 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10335 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 endif
10337 endif
10338
10339 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10340 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010341 exe 'NetrwKeepj '.w:netrw_bannercnt
10342 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 endif
10344 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010345 exe 'NetrwKeepj '.w:netrw_bannercnt
10346 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 endif
10348
10349 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010350 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010351" call Dret("NetrwRemoteFtpCmd")
10352endfun
10353
10354" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355" s:NetrwRemoteListing: {{{2
10356fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010357" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010358
Bram Moolenaara6878372014-03-22 21:02:50 +010010359 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10360 let w:netrw_bannercnt= s:bannercnt
10361 endif
10362 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010363 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 endif
10365
Bram Moolenaar446cb832008-06-24 21:56:24 +000010366 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010367
Bram Moolenaar446cb832008-06-24 21:56:24 +000010368 " sanity check:
10369 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010370" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010372" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373 if !exists("g:netrw_quiet")
10374 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10375 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010376 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010377" call Dret("s:NetrwRemoteListing -1")
10378 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380
Bram Moolenaar8d043172014-01-23 14:24:41 +010010381 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010384 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010385 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 +000010386 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010387 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 +000010388 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010389 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010390
Bram Moolenaar85850f32019-07-19 22:05:51 +020010391 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010392" call Dret("s:NetrwRemoteListing -1")
10393 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010396
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399 let w:netrw_method= b:netrw_method
10400 endif
10401
Bram Moolenaar13600302014-05-22 18:26:40 +020010402 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010403 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010404" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010405 let s:method = "ftp"
10406 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010407 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010409 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 let listcmd= g:netrw_ftp_sizelist_cmd
10411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415
Bram Moolenaara6878372014-03-22 21:02:50 +010010416 " report on missing file or directory messages
10417 if search('[Nn]o such file or directory\|Failed to change directory')
10418 let mesg= getline(".")
10419 if exists("w:netrw_bannercnt")
10420 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010421 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010422 setl noma
10423 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010424 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 call netrw#ErrorMsg(s:WARNING,mesg,96)
10426" call Dret("s:NetrwRemoteListing : -1")
10427 return -1
10428 endif
10429
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010430 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 +000010431 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010432" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010433 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434
10435 " cleanup
10436 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10438 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 sil! NetrwKeepj %s/\r$//e
10441 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010443 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010445 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010446 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010447" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 exe "sil! NetrwKeepj ".line1
10453 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010455" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10459 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010461" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10463 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10464 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10465 NetrwKeepj call histdel("/",-1)
10466 NetrwKeepj call histdel("/",-1)
10467 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 endif
10469 endif
10470
Bram Moolenaar13600302014-05-22 18:26:40 +020010471 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010473" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010474 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010477" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10478 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010480 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10481 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10482 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10483 NetrwKeepj call histdel("/",-1)
10484 NetrwKeepj call histdel("/",-1)
10485 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010487 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10488 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 endif
10490 else
10491 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010492" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010493 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10496 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10497" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498 endif
10499 endif
10500
10501 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010502 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10505 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506 endif
10507 endif
10508
10509 if w:netrw_liststyle == s:LONGLIST
10510 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010511" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512
10513 if s:method == "ftp"
10514 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010515 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010516 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010517 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010519 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010521 sil! NetrwKeepj 1
10522 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let line2= line(".")
10524 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010526 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 endif
10528 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe "sil! NetrwKeepj ".line1
10530 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 endif
10532
10533 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010534" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010535 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 +000010536 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10541 NetrwKeepj call histdel("/",-1)
10542 NetrwKeepj call histdel("/",-1)
10543 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endif
10545 endif
10546
10547" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010548" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010550
10551" call Dret("s:NetrwRemoteListing 0")
10552 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010553endfun
10554
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555" ---------------------------------------------------------------------
10556" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10557fun! s:NetrwRemoteRm(usrhost,path) range
10558" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010560 let svpos= winsaveview()
10561" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562
10563 let all= 0
10564 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10565 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 for fname in s:netrwmarkfilelist_{bufnr("%")}
10568 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010569 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010571 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572 let all= 1
10573 endif
10574 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010575 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576
10577 else
10578 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580
10581 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582 let keepsol = &l:sol
10583 setl nosol
10584 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585
10586 " remove multiple files and directories
10587 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010588 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010590 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010592 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 let all= 1
10594 endif
10595 let ctr= ctr + 1
10596 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010597 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 endif
10599
10600 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010601" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010602 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605
10606" call Dret("s:NetrwRemoteRm")
10607endfun
10608
10609" ---------------------------------------------------------------------
10610" s:NetrwRemoteRmFile: {{{2
10611fun! s:NetrwRemoteRmFile(path,rmfile,all)
10612" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10613
10614 let all= a:all
10615 let ok = ""
10616
10617 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10618 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010620 if !all
10621 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 call inputsave()
10624 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10625 call inputrestore()
10626 echohl NONE
10627 if ok == ""
10628 let ok="no"
10629 endif
10630 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010631 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 let all= 1
10633 endif
10634 endif
10635
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010636 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010637" 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 +000010638 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010641 if path =~ '^\a\{3,}://'
10642 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010644 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10646 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010647" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010651 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652 let ok="q"
10653 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010654 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10656" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10657" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010661 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665 if v:shell_error != 0
10666 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010667 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 +010010668 else
10669 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10670 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010671 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 endif
10676 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010677 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 endif
10680
10681 else
10682 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 if !all
10685 call inputsave()
10686 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10687 call inputrestore()
10688 if ok == ""
10689 let ok="no"
10690 endif
10691 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010692 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 let all= 1
10694 endif
10695 endif
10696
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010697 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010699 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700 else
10701 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010702 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10703" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010704 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706
10707 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10709 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10710" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010711 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713
10714 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010715 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716 endif
10717 endif
10718 endif
10719
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010720 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010722 endif
10723 endif
10724
10725" call Dret("s:NetrwRemoteRmFile ".ok)
10726 return ok
10727endfun
10728
10729" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730" s:NetrwRemoteRename: rename a remote file or directory {{{2
10731fun! s:NetrwRemoteRename(usrhost,path) range
10732" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10733
10734 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010735 let svpos = winsaveview()
10736" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737 let ctr = a:firstline
10738 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10739
10740 " rename files given by the markfilelist
10741 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10742 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010744 if exists("subfrom")
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 else
10748 call inputsave()
10749 let newname= input("Moving ".oldname." to : ",oldname)
10750 call inputrestore()
10751 if newname =~ '^s/'
10752 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10753 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10754 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010756 endif
10757 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010760 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762 let oldname= s:ShellEscape(a:path.oldname)
10763 let newname= s:ShellEscape(a:path.newname)
10764" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010765 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766 endif
10767
10768 endfor
10769 call s:NetrwUnMarkFile(1)
10770
10771 else
10772
10773 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010774 let keepsol= &l:sol
10775 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010777 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778
10779 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010780" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781
10782 call inputsave()
10783 let newname= input("Moving ".oldname." to : ",oldname)
10784 call inputrestore()
10785
10786 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10787 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10788 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010789 let oldname= s:ShellEscape(a:path.oldname)
10790 let newname= s:ShellEscape(a:path.newname)
10791" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010792 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010793 endif
10794
10795 let ctr= ctr + 1
10796 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010798 endif
10799
10800 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010801 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010802" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10803 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010804
10805" call Dret("NetrwRemoteRename")
10806endfun
10807
Bram Moolenaar85850f32019-07-19 22:05:51 +020010808" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010809" Local Directory Browsing Support: {{{1
10810" ==========================================
10811
10812" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010813" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010814" Should accept: file://localhost/etc/fstab
10815" file:///etc/fstab
10816" file:///c:/WINDOWS/clock.avi
10817" file:///c|/WINDOWS/clock.avi
10818" file://localhost/c:/WINDOWS/clock.avi
10819" file://localhost/c|/WINDOWS/clock.avi
10820" file://c:/foo.txt
10821" file:///c:/foo.txt
10822" 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 +020010823fun! netrw#FileUrlEdit(fname)
10824" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825 let fname = a:fname
10826 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010827" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010831 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010832 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010834 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 endif
10837 endif
10838 let fname2396 = netrw#RFC2396(fname)
10839 let fname2396e= fnameescape(fname2396)
10840 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010841 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10846 endif
10847 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010848
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10850" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010852 exe 'NetrwKeepj keepalt edit '.plainfname
10853 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10854
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" 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 +020010856" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010857 exe "sil doau BufReadPost ".fname2396e
10858endfun
10859
10860" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010861" netrw#LocalBrowseCheck: {{{2
10862fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010863 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010864 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10865 "
10866 " unfortunate interaction -- split window debugging can't be used here, must use
10867 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10868 " another call to LocalBrowseCheck() when attempts to write
10869 " to the DBG buffer are made.
10870 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010871 " The &ft == "netrw" test was installed because the BufEnter event
10872 " would hit when re-entering netrw windows, creating unexpected
10873 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010874" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010875" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876" 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 +010010877 " getting E930: Cannot use :redir inside execute
10878"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10880" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010881
Bram Moolenaar97d62492012-11-15 21:28:22 +010010882 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883 if isdirectory(s:NetrwFile(a:dirname))
10884" 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 +010010885
Bram Moolenaar97d62492012-11-15 21:28:22 +010010886 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10888" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010889 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010890
Bram Moolenaar446cb832008-06-24 21:56:24 +000010891 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010893 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010894
Bram Moolenaar5c736222010-01-06 20:54:52 +010010895 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010897 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010898 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900" 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 +010010901" call Dret("netrw#LocalBrowseCheck")
10902 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010903 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010904
Bram Moolenaar85850f32019-07-19 22:05:51 +020010905 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010906 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10907 " AND IF the listing style is not a tree listing
10908 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010910 let ibuf = 1
10911 let buflast = bufnr("$")
10912 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10914 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010915 endif
10916 let ibuf= ibuf + 1
10917 endwhile
10918 endif
10919 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" 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>"))
10921" 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 +000010922 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010923" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924endfun
10925
10926" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010927" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010928" performed any shell command. The idea is to cause all local-browsing
10929" buffers to be refreshed after a user has executed some shell command,
10930" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010931fun! s:LocalBrowseRefresh()
10932" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010933" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10934" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010935
Bram Moolenaar446cb832008-06-24 21:56:24 +000010936 " determine which buffers currently reside in a tab
10937 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010938" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 return
10940 endif
10941 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010942" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943 return
10944 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010945 if !empty(getcmdwintype())
10946 " cannot move away from cmdline window, see :h E11
10947 return
10948 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010949 if exists("s:netrw_events") && s:netrw_events == 1
10950 " s:LocalFastBrowser gets called (indirectly) from a
10951 let s:netrw_events= 2
10952" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10953 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010954 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010955 let itab = 1
10956 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010957 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 while itab <= tabpagenr("$")
10959 let buftablist = buftablist + tabpagebuflist()
10960 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010961 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10964" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10966 " | refresh any netrw window
10967 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010968 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 let ibl = 0
10970 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010971" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10973 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010974 " (ibuf not shown in a current window AND
10975 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10977 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 continue
10981 elseif index(tabpagebuflist(),ibuf) != -1
10982 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010983" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010985 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010986 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10987 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10988 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10989 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010991 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10992 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10993 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010994 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995 endif
10996 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010999" call Decho("restore window: win_gotoid(".curwinid.")")
11000 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011001 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011002
Bram Moolenaara6878372014-03-22 21:02:50 +010011003" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011004endfun
11005
11006" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011007" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11008"
11009" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011011" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11012" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014"
11015" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11016" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011017" (re-using a buffer may not be as accurate)
11018"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011019" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011020" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11021" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11022" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11023" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011025" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11026" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11027" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11028" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011029
11030 " initialize browselist, a list of buffer numbers that the local browser has used
11031 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011032" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011033 let s:netrw_browselist= []
11034 endif
11035
11036 " append current buffer to fastbrowse list
11037 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011039 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011040" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011041 endif
11042
11043 " enable autocmd events to handle refreshing/removing local browser buffers
11044 " If local browse buffer is currently showing: refresh it
11045 " If local browse buffer is currently hidden : wipe it
11046 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11047 " =1 : medium speed, re-use directory listing for remote only
11048 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011049 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11050 let s:netrw_events= 1
11051 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011053 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011055 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011056 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 endif
11060 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011061
11062 " user must have changed fastbrowse to its fast setting, so remove
11063 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011066 unlet s:netrw_events
11067 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068 au!
11069 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011070 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071 endif
11072
Bram Moolenaar85850f32019-07-19 22:05:51 +020011073" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074endfun
11075
11076" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011077" s:LocalListing: does the job of "ls" for local directories {{{2
11078fun! s:LocalListing()
11079" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11081" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11082" 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 +010011083
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011084" 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
11085" 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
11086" 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 +010011087
11088 " get the list of files contained in the current directory
11089 let dirname = b:netrw_curdir
11090 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011091 let filelist = s:NetrwGlob(dirname,"*",0)
11092 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011094
Nir Lichtman1e34b952024-05-08 19:19:34 +020011095 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011097 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11098 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011102 endif
11103
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011104" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011106" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107
11108 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11109 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11110 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11112" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" 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 +010011115
11116 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" call Decho(" ",'~'.expand("<slnum>"))
11118" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119
11120 if getftype(filename) == "link"
11121 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123 let pfile= filename."@"
11124
11125 elseif getftype(filename) == "socket"
11126 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011128 let pfile= filename."="
11129
11130 elseif getftype(filename) == "fifo"
11131 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011132" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011133 let pfile= filename."|"
11134
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 let pfile= filename."/"
11139
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011141 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011142 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11143 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 let pfile= filename."*"
11146 else
11147 " normal file
11148 let pfile= filename
11149 endif
11150 elseif executable(filename)
11151 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 let pfile= filename."*"
11154 else
11155 " normal file
11156 let pfile= filename
11157 endif
11158
11159 else
11160 " normal file
11161 let pfile= filename
11162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011163" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011164
11165 if pfile =~ '//$'
11166 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011168 endif
11169 let pfile= strpart(pfile,dirnamelen)
11170 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011171" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11172" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011173
11174 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011175 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11176 let sz = getfsize(filename)
11177 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11178 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011179
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011180 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011181 let sz= s:NetrwHumanReadable(sz)
11182 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011183 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011184 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011185" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011186 endif
11187
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011188 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011190 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011191" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011192" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011194 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011195" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011197 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011198
11199 elseif g:netrw_sort_by =~ "^s"
11200 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011201" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011202" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011204 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011207 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011208
11209 else
11210 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011211" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011212" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011213 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011215" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 endfor
11217
11218 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011219 sil! NetrwKeepj g/^$/d
11220 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011221 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011223 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11224
11225" call Dret("s:LocalListing")
11226endfun
11227
11228" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011229" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11230fun! s:NetrwLocalExecute(cmd)
11231" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11232 let ykeep= @@
11233 " sanity check
11234 if !executable(a:cmd)
11235 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11236 let @@= ykeep
11237" call Dret("s:NetrwLocalExecute")
11238 return
11239 endif
11240
11241 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011242" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011243 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011244" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245
11246 " strip any ansi escape sequences off
11247 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11248
11249 " show user the result(s)
11250 echomsg result
11251 let @@= ykeep
11252
11253" call Dret("s:NetrwLocalExecute")
11254endfun
11255
11256" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011257" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258fun! s:NetrwLocalRename(path) range
11259" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11260
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011261 if !exists("w:netrw_bannercnt")
11262 let w:netrw_bannercnt= b:netrw_bannercnt
11263 endif
11264
Bram Moolenaar97d62492012-11-15 21:28:22 +010011265 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011266 let ykeep = @@
11267 let ctr = a:firstline
11268 let svpos = winsaveview()
11269 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011270" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011271
11272 " rename files given by the markfilelist
11273 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11274 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011275" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011276 if exists("subfrom")
11277 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011278" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 else
11280 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011281 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011283 if newname =~ ''
11284 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11285 let newname = substitute(newname,'^.*','','')
11286 elseif newname =~ ''
11287 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11288 let newname = substitute(newname,'[^/]*','','')
11289 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 if newname =~ '^s/'
11291 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11292 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011293" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011294 let newname = substitute(oldname,subfrom,subto,'')
11295 endif
11296 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011297 if !all && filereadable(newname)
11298 call inputsave()
11299 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11300 call inputrestore()
11301 if response == "all"
11302 let all= 1
11303 elseif response != "y" && response != "yes"
11304 " refresh the directory
11305" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11306 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11307" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11308 NetrwKeepj call winrestview(svpos)
11309 let @@= ykeep
11310" call Dret("NetrwLocalRename")
11311 return
11312 endif
11313 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011314 call rename(oldname,newname)
11315 endfor
11316 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011317
Bram Moolenaar97d62492012-11-15 21:28:22 +010011318 else
11319
11320 " attempt to rename files/directories
11321 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011322 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011323
11324 " sanity checks
11325 if line(".") < w:netrw_bannercnt
11326 let ctr= ctr + 1
11327 continue
11328 endif
11329 let curword= s:NetrwGetWord()
11330 if curword == "./" || curword == "../"
11331 let ctr= ctr + 1
11332 continue
11333 endif
11334
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011335 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011336 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011337" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011338
11339 call inputsave()
11340 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11341 call inputrestore()
11342
11343 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011344" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011345
11346 let ctr= ctr + 1
11347 endwhile
11348 endif
11349
11350 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011351" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011352 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011353" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11354 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011355 let @@= ykeep
11356
11357" call Dret("NetrwLocalRename")
11358endfun
11359
11360" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361" s:NetrwLocalRm: {{{2
11362fun! s:NetrwLocalRm(path) range
11363" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011364" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011365
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011366 if !exists("w:netrw_bannercnt")
11367 let w:netrw_bannercnt= b:netrw_bannercnt
11368 endif
11369
Bram Moolenaar446cb832008-06-24 21:56:24 +000011370 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011371 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011372 let ret = 0
11373 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011374 let svpos = winsaveview()
11375" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376
11377 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11378 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011379" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 for fname in s:netrwmarkfilelist_{bufnr("%")}
11381 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011382 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011383 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011384 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 let all= 1
11386 endif
11387 endfor
11388 call s:NetrwUnMarkFile(1)
11389
11390 else
11391 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011392" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394 let keepsol= &l:sol
11395 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 let ctr = a:firstline
11397 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011398 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399
11400 " sanity checks
11401 if line(".") < w:netrw_bannercnt
11402 let ctr= ctr + 1
11403 continue
11404 endif
11405 let curword= s:NetrwGetWord()
11406 if curword == "./" || curword == "../"
11407 let ctr= ctr + 1
11408 continue
11409 endif
11410 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011411 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011413 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 let all= 1
11415 endif
11416 let ctr= ctr + 1
11417 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011418 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419 endif
11420
11421 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011422" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011423 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011424 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011425" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11426 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011428 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429
11430" call Dret("s:NetrwLocalRm")
11431endfun
11432
11433" ---------------------------------------------------------------------
11434" s:NetrwLocalRmFile: remove file fname given the path {{{2
11435" Give confirmation prompt unless all==1
11436fun! s:NetrwLocalRmFile(path,fname,all)
11437" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011438
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439 let all= a:all
11440 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011441 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011442 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011443" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011444
11445 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11446 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011448 if !all
11449 echohl Statement
11450 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011451 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 call inputrestore()
11453 echohl NONE
11454 if ok == ""
11455 let ok="no"
11456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011457" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011460 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 let all= 1
11462 endif
11463 endif
11464
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011465 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011466 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 endif
11469
11470 else
11471 " attempt to remove directory
11472 if !all
11473 echohl Statement
11474 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011475 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011476 call inputrestore()
11477 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11478 if ok == ""
11479 let ok="no"
11480 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011481 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011482 let all= 1
11483 endif
11484 endif
11485 let rmfile= substitute(rmfile,'[\/]$','','e')
11486
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011487 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011488 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011489 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011490 endif
11491 endif
11492 endif
11493
11494" call Dret("s:NetrwLocalRmFile ".ok)
11495 return ok
11496endfun
11497
Bram Moolenaar85850f32019-07-19 22:05:51 +020011498" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011499" Support Functions: {{{1
11500
Bram Moolenaar488c6512005-08-11 20:09:58 +000011501" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011502" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11503" 0: marked file list of current buffer
11504" 1: marked file target
11505fun! netrw#Access(ilist)
11506 if a:ilist == 0
11507 if exists("s:netrwmarkfilelist_".bufnr('%'))
11508 return s:netrwmarkfilelist_{bufnr('%')}
11509 else
11510 return "no-list-buf#".bufnr('%')
11511 endif
11512 elseif a:ilist == 1
11513 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011514 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011515endfun
11516
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011517" ---------------------------------------------------------------------
11518" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11519fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011520 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011521endfun
11522
Bram Moolenaara6878372014-03-22 21:02:50 +010011523" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011524" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11525" I expect this function to be used in
11526" :PChkAssert netrw#Expose("netrwmarkfilelist")
11527" for example.
11528fun! netrw#Expose(varname)
11529" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011530 if exists("s:".a:varname)
11531 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011532" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011533 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011534" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011535 if type(retval) == 3
11536 let retval = copy(retval)
11537 let i = 0
11538 while i < len(retval)
11539 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11540 let i = i + 1
11541 endwhile
11542 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011543" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011544 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011545 else
11546" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011548 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011549" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011550 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011551 endif
11552
11553" call Dret("netrw#Expose ".string(retval))
11554 return retval
11555endfun
11556
11557" ---------------------------------------------------------------------
11558" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11559fun! netrw#Modify(varname,newvalue)
11560" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11561 exe "let s:".a:varname."= ".string(a:newvalue)
11562" call Dret("netrw#Modify")
11563endfun
11564
11565" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011566" netrw#RFC2396: converts %xx into characters {{{2
11567fun! netrw#RFC2396(fname)
11568" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011569 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011570" call Dret("netrw#RFC2396 ".fname)
11571 return fname
11572endfun
11573
11574" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011575" netrw#UserMaps: supports user-specified maps {{{2
11576" see :help function()
11577"
11578" g:Netrw_UserMaps is a List with members such as:
11579" [[keymap sequence, function reference],...]
11580"
11581" The referenced function may return a string,
11582" refresh : refresh the display
11583" -other- : this string will be executed
11584" or it may return a List of strings.
11585"
11586" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011587" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011588" Related functions:
11589" netrw#Expose(varname) -- see s:varname variables
11590" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11591" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11592fun! netrw#UserMaps(islocal)
11593" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11594" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11595
11596 " set up usermaplist
11597 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11598" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11599 for umap in g:Netrw_UserMaps
11600" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11601" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11602 " if umap[0] is a string and umap[1] is a string holding a function name
11603 if type(umap[0]) == 1 && type(umap[1]) == 1
11604" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11605 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11606 else
11607 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11608 endif
11609 endfor
11610 endif
11611" call Dret("netrw#UserMaps")
11612endfun
11613
11614" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011615" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11616fun! netrw#WinPath(path)
11617" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011618 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011619 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011620 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011621 " remove trailing slash (Win95)
11622 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11623 " remove escaped spaces
11624 let path = substitute(path, '\ ', ' ', 'g')
11625 " convert slashes to backslashes
11626 let path = substitute(path, '/', '\', 'g')
11627 else
11628 let path= a:path
11629 endif
11630" call Dret("netrw#WinPath <".path.">")
11631 return path
11632endfun
11633
11634" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011635" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11636fun! s:StripTrailingSlash(path)
11637 " remove trailing slash
11638 return substitute(a:path, '[/\\]$', '', 'g')
11639endfun
11640
Travis Sheltone34d0e32024-07-30 21:08:56 +020011641" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011642" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11643" cb : bl2mf=0 add marked files to buffer list
11644" cB : bl2mf=1 use bufferlist to mark files
11645" (mnemonic: cb = copy (marked files) to buffer list)
11646fun! s:NetrwBadd(islocal,bl2mf)
11647" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11648 if a:bl2mf
11649 " cB: add buffer list to marked files
11650 redir => bufl
11651 ls
11652 redir END
11653 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11654 for fname in bufl
11655 call s:NetrwMarkFile(a:islocal,fname)
11656 endfor
11657 else
11658 " cb: add marked files to buffer list
11659 for fname in s:netrwmarkfilelist_{bufnr("%")}
11660" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11661 exe "badd ".fnameescape(fname)
11662 endfor
11663 let curbufnr = bufnr("%")
11664 let curdir = s:NetrwGetCurdir(a:islocal)
11665 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11666 endif
11667" call Dret("s:NetrwBadd")
11668endfun
11669
11670" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011671" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11672fun! s:ComposePath(base,subdir)
11673" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11674
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011675 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011676" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011677 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011678 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011679 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011680 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011681 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011682 endif
11683
Bram Moolenaar85850f32019-07-19 22:05:51 +020011684 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011685 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011687 let ret= a:subdir
11688
Nir Lichtman1e34b952024-05-08 19:19:34 +020011689 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011690" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011691 if a:base =~ '[/\\]$'
11692 let ret= a:base.a:subdir
11693 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011695 endif
11696
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697 elseif a:base =~ '^\a\{3,}://'
11698" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011699 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11700 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11701 if a:subdir == '../'
11702 if curpath =~ '[^/]/[^/]\+/$'
11703 let curpath= substitute(curpath,'[^/]\+/$','','')
11704 else
11705 let curpath=""
11706 endif
11707 let ret= urlbase.curpath
11708 else
11709 let ret= urlbase.curpath.a:subdir
11710 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011711" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11712" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11713" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011714
11715 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011716" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011717 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11718 if a:base =~ '^//'
11719 " keeping initial '//' for the benefit of network share listing support
11720 let ret= '/'.ret
11721 endif
11722 let ret= simplify(ret)
11723 endif
11724
11725" call Dret("s:ComposePath ".ret)
11726 return ret
11727endfun
11728
11729" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011730" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11731" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11732fun! s:DeleteBookmark(fname)
11733" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11734 call s:MergeBookmarks()
11735
11736 if exists("g:netrw_bookmarklist")
11737 let indx= index(g:netrw_bookmarklist,a:fname)
11738 if indx == -1
11739 let indx= 0
11740 while indx < len(g:netrw_bookmarklist)
11741 if g:netrw_bookmarklist[indx] =~ a:fname
11742 call remove(g:netrw_bookmarklist,indx)
11743 let indx= indx - 1
11744 endif
11745 let indx= indx + 1
11746 endwhile
11747 else
11748 " remove exact match
11749 call remove(g:netrw_bookmarklist,indx)
11750 endif
11751 endif
11752
11753" call Dret("s:DeleteBookmark")
11754endfun
11755
11756" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011757" s:FileReadable: o/s independent filereadable {{{2
11758fun! s:FileReadable(fname)
11759" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11760
11761 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011762 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011763 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011764 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011765 endif
11766
11767" call Dret("s:FileReadable ".ret)
11768 return ret
11769endfun
11770
11771" ---------------------------------------------------------------------
11772" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11773" Places correct suffix on end of temporary filename,
11774" using the suffix provided with fname
11775fun! s:GetTempfile(fname)
11776" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11777
11778 if !exists("b:netrw_tmpfile")
11779 " get a brand new temporary filename
11780 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011781" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011782
Bram Moolenaarc236c162008-07-13 17:41:49 +000011783 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011785
Bram Moolenaar9964e462007-05-05 17:54:07 +000011786 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11788" 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 +010011789 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011790" call Dret("s:GetTempfile getcwd<".getcwd().">")
11791 return ""
11792 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011793
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011795 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011796" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011797
Bram Moolenaar9964e462007-05-05 17:54:07 +000011798 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011799 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011800 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011801 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802 if !exists("+shellslash") || !&ssl
11803 let tmpfile = substitute(tmpfile,'/','\','g')
11804 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011806 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011807 endif
11808 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011809" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 else
11811 " re-use temporary filename
11812 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011813" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 endif
11815
11816 " use fname's suffix for the temporary file
11817 if a:fname != ""
11818 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011819" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011820 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011821 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011822 elseif a:fname =~ '.txz$'
11823 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 else
11825 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11826 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011830 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11833 endif
11834 endif
11835
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" 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 +000011837" call Dret("s:GetTempfile <".tmpfile.">")
11838 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011839endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840
11841" ---------------------------------------------------------------------
11842" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011843" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011844fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011845" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011846 if s:user == ""
11847 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11848 else
11849 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11850 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011851 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011852 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011853 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011854 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011855 else
11856 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11857 endif
11858" call Dret("s:MakeSshCmd <".sshcmd.">")
11859 return sshcmd
11860endfun
11861
11862" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011863" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11864fun! s:MakeBookmark(fname)
11865" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11866
11867 if !exists("g:netrw_bookmarklist")
11868 let g:netrw_bookmarklist= []
11869 endif
11870
11871 if index(g:netrw_bookmarklist,a:fname) == -1
11872 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011874 call add(g:netrw_bookmarklist,a:fname.'/')
11875 elseif a:fname !~ '/'
11876 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11877 else
11878 call add(g:netrw_bookmarklist,a:fname)
11879 endif
11880 call sort(g:netrw_bookmarklist)
11881 endif
11882
11883" call Dret("s:MakeBookmark")
11884endfun
11885
11886" ---------------------------------------------------------------------
11887" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11888fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011889" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011890 " get bookmarks from .netrwbook file
11891 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892 if filereadable(s:NetrwFile(savefile))
11893" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011894 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011896 NetrwKeepj call delete(savefile)
11897 endif
11898" call Dret("s:MergeBookmarks")
11899endfun
11900
11901" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011902" s:NetrwBMShow: {{{2
11903fun! s:NetrwBMShow()
11904" call Dfunc("s:NetrwBMShow()")
11905 redir => bmshowraw
11906 menu
11907 redir END
11908 let bmshowlist = split(bmshowraw,'\n')
11909 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011910 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011911 if bmshowfuncs != []
11912 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011913 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011914 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011915 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011916 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011917 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11919endfun
11920
11921" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011922" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011923fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011924 if !exists("w:netrw_liststyle")
11925 let w:netrw_liststyle= g:netrw_liststyle
11926 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011927" 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 +020011928
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011929" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11930
Bram Moolenaaradc21822011-04-01 18:03:16 +020011931 if &ft != "netrw"
11932 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11933 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011934" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011935
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011936 elseif g:netrw_cursor == 8
11937 if w:netrw_liststyle == s:WIDELIST
11938 setl cursorline
11939 setl cursorcolumn
11940 else
11941 setl cursorline
11942 endif
11943 elseif g:netrw_cursor == 7
11944 setl cursorline
11945 elseif g:netrw_cursor == 6
11946 if w:netrw_liststyle == s:WIDELIST
11947 setl cursorline
11948 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011949 elseif g:netrw_cursor == 4
11950 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011952 setl cursorline
11953 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011954
11955 elseif g:netrw_cursor == 3
11956 " thin-long-tree: cursorline, user's cursorcolumn
11957 " wide : cursorline, cursorcolumn
11958 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011959" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011960 setl cursorline
11961 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011962 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011963" 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 +020011964 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 endif
11966
11967 elseif g:netrw_cursor == 2
11968 " thin-long-tree: cursorline, user's cursorcolumn
11969 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011971 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972
11973 elseif g:netrw_cursor == 1
11974 " thin-long-tree: user's cursorline, user's cursorcolumn
11975 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011976 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011977" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011978 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011981 endif
11982
11983 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011985" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986 let &l:cursorline = s:netrw_usercul
11987 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011988 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011990" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011991" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011992endfun
11993
11994" ---------------------------------------------------------------------
11995" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11996fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011997" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011998 if exists("s:netrw_usercul")
11999 let &l:cursorline = s:netrw_usercul
12000 endif
12001 if exists("s:netrw_usercuc")
12002 let &l:cursorcolumn = s:netrw_usercuc
12003 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012004" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012005" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12006endfun
12007
Christian Brabandt62f7b552024-06-23 20:23:40 +020012008" s:RestoreRegister: restores all registers given in the dict {{{2
12009fun! s:RestoreRegister(dict)
12010 for [key, val] in items(a:dict)
12011 if key == 'unnamed'
12012 let key = ''
12013 endif
12014 call setreg(key, val[0], val[1])
12015 endfor
12016endfun
12017
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012018" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012019" s:NetrwDelete: Deletes a file. {{{2
12020" Uses Steve Hall's idea to insure that Windows paths stay
12021" acceptable. No effect on Unix paths.
12022" Examples of use: let result= s:NetrwDelete(path)
12023fun! s:NetrwDelete(path)
12024" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12025
Bram Moolenaar5c736222010-01-06 20:54:52 +010012026 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012027 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012028 if exists("+shellslash")
12029 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012030 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031 let result = delete(path)
12032 let &shellslash = sskeep
12033 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012034" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 let result= delete(path)
12036 endif
12037 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012038" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 let result= delete(path)
12040 endif
12041 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012042 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012043 endif
12044
12045" call Dret("s:NetrwDelete ".result)
12046 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012047endfun
12048
12049" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012050" s:NetrwBufRemover: removes a buffer that: {{{2s
12051" has buffer-id > 1
12052" is unlisted
12053" is unnamed
12054" does not appear in any window
12055fun! s:NetrwBufRemover(bufid)
12056" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12057" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12058" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12059" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12060" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12061
yasuda4dbb2662023-10-04 20:50:35 +020012062 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012063" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012064 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012065 endif
12066
12067" call Dret("s:NetrwBufRemover")
12068endfun
12069
12070" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012071" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012072fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012073" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012074" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012075
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012076 " Clean out the last buffer:
12077 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12078 " If so, delete it.
12079 call s:NetrwBufRemover(bufnr("$"))
12080
Bram Moolenaar446cb832008-06-24 21:56:24 +000012081 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012082" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012083 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12084 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12085 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12086 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12087 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12088 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12089 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12090 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12091 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12092 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12093 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12094 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12095 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12096 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12097 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12098 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12099
Bram Moolenaar85850f32019-07-19 22:05:51 +020012100 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012101" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012102 " when tree listing uses file TreeListing... a new buffer is made.
12103 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012104 " COMBAK: this causes a problem, see P43
12105" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012106 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012107 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012108 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012109" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012110 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012111
Bram Moolenaar446cb832008-06-24 21:56:24 +000012112 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012113" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012114 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12115 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12116 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12117 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12118 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12119 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12120 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12121 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12122 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12123 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12124 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12125 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12126 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12127 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12128 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12129 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12130
Bram Moolenaar5c736222010-01-06 20:54:52 +010012131 if a:0 > 0
12132 let b:netrw_curdir= a:1
12133 if b:netrw_curdir =~ '/$'
12134 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012135 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012136 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012137 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012138 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12139 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012140 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012141 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012143 endif
12144 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012145 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12146 let &l:bexpr = "netrw#BalloonHelp()"
12147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012148
Bram Moolenaar8d043172014-01-23 14:24:41 +010012149" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012150endfun
12151
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012152" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012153" s:NetrwExe: executes a string using "!" {{{2
12154fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012155" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012156 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012157" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012158 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12159 set shell& shellcmdflag& shellxquote& shellxescape&
12160 set shellquote& shellpipe& shellredir& shellslash&
12161 exe a:cmd
12162 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12163 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012165 exe a:cmd
12166 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012167 if v:shell_error
12168 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12169 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012170" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012171endfun
12172
12173" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012174" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12175fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012176 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012177" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012178 let curbuf = bufnr("%")
12179 let curwin = winnr()
12180 let iwin = 1
12181 while iwin <= winnr("$")
12182 exe iwin."wincmd w"
12183 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12184 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12185 let winvars= w:
12186 break
12187 endif
12188 let iwin= iwin + 1
12189 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012190 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012191 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012192" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012193 for k in keys(winvars)
12194 let w:{k}= winvars[k]
12195 endfor
12196 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012197" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012198 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012199endfun
12200
Bram Moolenaara6878372014-03-22 21:02:50 +010012201" ---------------------------------------------------------------------
12202" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012203" Returns: 0=success
12204" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012205fun! s:NetrwLcd(newdir)
12206" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012207" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012208
Bram Moolenaar85850f32019-07-19 22:05:51 +020012209 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012210 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012211 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012212 catch /^Vim\%((\a\+)\)\=:E344/
12213 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12214 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012215 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012216 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12217 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012218 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012219 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12220 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012221 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 endif
12223 endif
12224 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012225 let err472= 1
12226 endtry
12227
12228 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12230 if exists("w:netrw_prvdir")
12231 let a:newdir= w:netrw_prvdir
12232 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012233 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012234" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012235 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012236" 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 +010012237 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012239" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12240 return -1
12241 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012242
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012243" call Decho("getcwd <".getcwd().">")
12244" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012245" call Dret("s:NetrwLcd 0")
12246 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012247endfun
12248
Bram Moolenaar9964e462007-05-05 17:54:07 +000012249" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012250" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12251" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12252fun! s:NetrwSaveWordPosn()
12253" call Dfunc("NetrwSaveWordPosn()")
12254 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12255" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12256endfun
12257
12258" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012259" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12260" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12261fun! s:NetrwHumanReadable(sz)
12262" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12263
12264 if g:netrw_sizestyle == 'h'
12265 if a:sz >= 1000000000
12266 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12267 elseif a:sz >= 10000000
12268 let sz = printf("%d",a:sz/1000000)."m"
12269 elseif a:sz >= 1000000
12270 let sz = printf("%.1f",a:sz/1000000.0)."m"
12271 elseif a:sz >= 10000
12272 let sz = printf("%d",a:sz/1000)."k"
12273 elseif a:sz >= 1000
12274 let sz = printf("%.1f",a:sz/1000.0)."k"
12275 else
12276 let sz= a:sz
12277 endif
12278
12279 elseif g:netrw_sizestyle == 'H'
12280 if a:sz >= 1073741824
12281 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12282 elseif a:sz >= 10485760
12283 let sz = printf("%d",a:sz/1048576)."M"
12284 elseif a:sz >= 1048576
12285 let sz = printf("%.1f",a:sz/1048576.0)."M"
12286 elseif a:sz >= 10240
12287 let sz = printf("%d",a:sz/1024)."K"
12288 elseif a:sz >= 1024
12289 let sz = printf("%.1f",a:sz/1024.0)."K"
12290 else
12291 let sz= a:sz
12292 endif
12293
12294 else
12295 let sz= a:sz
12296 endif
12297
12298" call Dret("s:NetrwHumanReadable ".sz)
12299 return sz
12300endfun
12301
12302" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012303" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12304" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12305fun! s:NetrwRestoreWordPosn()
12306" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012307 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012308" call Dret("NetrwRestoreWordPosn")
12309endfun
12310
12311" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012312" s:RestoreBufVars: {{{2
12313fun! s:RestoreBufVars()
12314" call Dfunc("s:RestoreBufVars()")
12315
12316 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12317 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12318 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12319 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12320 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12321 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12322
12323" call Dret("s:RestoreBufVars")
12324endfun
12325
12326" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012327" s:RemotePathAnalysis: {{{2
12328fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012329" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012330
Bram Moolenaara6878372014-03-22 21:02:50 +010012331 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012332 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012333 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012334 let s:user = substitute(a:dirname,dirpat,'\3','')
12335 let s:machine = substitute(a:dirname,dirpat,'\4','')
12336 let s:port = substitute(a:dirname,dirpat,'\5','')
12337 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012338 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012339 if s:machine =~ '@'
12340 let dirpat = '^\(.*\)@\(.\{-}\)$'
12341 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12342 let s:machine = substitute(s:machine,dirpat,'\2','')
12343 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012344
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12346" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12347" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12348" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12349" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12350" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012351
12352" call Dret("s:RemotePathAnalysis")
12353endfun
12354
12355" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012356" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12357" Returns status
12358" Runs system() on
12359" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012360" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012361fun! s:RemoteSystem(cmd)
12362" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12363 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012364 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 +000012365 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012366 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012367 else
12368 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12369 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12370 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012371 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012372 else
12373 let cmd= cmd.' '
12374 endif
12375 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012376" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012377 let ret= system(cmd)
12378 endif
12379" call Dret("s:RemoteSystem ".ret)
12380 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012381endfun
12382
12383" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012384" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012385fun! s:RestoreWinVars()
12386" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012387 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12389 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12390 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12391 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12392 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12393 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12394 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12395 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12396 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12397 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12398 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12399 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012400 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12401 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012402 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12403 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12404 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12405" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012406endfun
12407
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012408" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012409" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12410"
12411" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12412" is true) and a command, :Rexplore, which call this function.
12413"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012414" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012415"
12416" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012417fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012418 if exists("s:netrwdrag")
12419 return
12420 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012421" 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 +010012422" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12423" 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 +010012424
12425 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012426 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012428 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012429 unlet w:netrw_rexfile
12430" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012431 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012432" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012433" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12434" 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 +020012435 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012436
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012437 " ---------------------------
12438 " :Rex issued while in a file
12439 " ---------------------------
12440
Bram Moolenaara6878372014-03-22 21:02:50 +010012441 " record current file so :Rex can return to it from netrw
12442 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012443" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012444
12445 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012446" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012447 return
12448 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012449" 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 +020012450 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012451 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012453 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012454 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012455 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012456 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012457 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012458 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12460 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012461" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12462 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012463 if exists("s:rexposn_".bufnr('%'))
12464 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012465 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012467" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012468 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012469
Bram Moolenaar85850f32019-07-19 22:05:51 +020012470 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12471 if exists("s:explore_match")
12472 exe "2match netrwMarkFile /".s:explore_match."/"
12473 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012474 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012475
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012476" 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 +010012477" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012478endfun
12479
12480" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012481" s:SaveBufVars: save selected b: variables to s: variables {{{2
12482" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012483fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012484" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012485
12486 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12487 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12488 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12489 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12490 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12491 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12492
12493" call Dret("s:SaveBufVars")
12494endfun
12495
12496" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012497" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12498fun! s:SavePosn(posndict)
12499" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12500
Bram Moolenaar85850f32019-07-19 22:05:51 +020012501 if !exists("a:posndict[bufnr('%')]")
12502 let a:posndict[bufnr("%")]= []
12503 endif
12504" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12505 call add(a:posndict[bufnr("%")],winsaveview())
12506" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012507
12508" call Dret("s:SavePosn posndict")
12509 return a:posndict
12510endfun
12511
12512" ---------------------------------------------------------------------
12513" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12514fun! s:RestorePosn(posndict)
12515" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012516 if exists("a:posndict")
12517 if has_key(a:posndict,bufnr("%"))
12518" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12519 let posnlen= len(a:posndict[bufnr("%")])
12520 if posnlen > 0
12521 let posnlen= posnlen - 1
12522" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12523 call winrestview(a:posndict[bufnr("%")][posnlen])
12524 call remove(a:posndict[bufnr("%")],posnlen)
12525" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12526 endif
12527 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012528 endif
12529" call Dret("s:RestorePosn")
12530endfun
12531
12532" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012533" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012534fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012535" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012536 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12537 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12538 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12539 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12540 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12541 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12542 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12543 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12544 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12545 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12546 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12547 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12548 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12549 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12550 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12551 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12552 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12553 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12554" call Dret("s:SaveWinVars")
12555endfun
12556
12557" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012558" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012559" To allow separate windows to have their own activities, such as
12560" Explore **/pattern, several variables have been made window-oriented.
12561" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012562" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012563" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012564fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012565" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012566 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12567 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12568 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12569 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12570 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12571 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12572 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12573 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12574 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12575 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12576" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012577endfun
12578
12579" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012580" s:SetRexDir: set directory for :Rexplore {{{2
12581fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012582" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012583 let w:netrw_rexdir = a:dirname
12584 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012585 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012586" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12587" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012588" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012589" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012590" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012591endfun
12592
12593" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012594" s:ShowLink: used to modify thin and tree listings to show links {{{2
12595fun! s:ShowLink()
12596" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012597" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12598" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012599 if exists("b:netrw_curdir")
12600 norm! $?\a
12601 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12602 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012603" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12604" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12605" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12606 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012607 let dirlen = strlen(b:netrw_curdir)
12608 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012609" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012610 endif
12611 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12613" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012614 setl noro ma
12615 call setline(".",modline)
12616 setl ro noma nomod
12617 endif
12618" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12619endfun
12620
12621" ---------------------------------------------------------------------
12622" s:ShowStyle: {{{2
12623fun! s:ShowStyle()
12624 if !exists("w:netrw_liststyle")
12625 let liststyle= g:netrw_liststyle
12626 else
12627 let liststyle= w:netrw_liststyle
12628 endif
12629 if liststyle == s:THINLIST
12630 return s:THINLIST.":thin"
12631 elseif liststyle == s:LONGLIST
12632 return s:LONGLIST.":long"
12633 elseif liststyle == s:WIDELIST
12634 return s:WIDELIST.":wide"
12635 elseif liststyle == s:TREELIST
12636 return s:TREELIST.":tree"
12637 else
12638 return 'n/a'
12639 endif
12640endfun
12641
12642" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12644" Solution from Nicolai Weibull, vim docs (:help strlen()),
12645" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012646fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012647" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12648
12649 if v:version >= 703 && exists("*strdisplaywidth")
12650 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012651
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 elseif type(g:Align_xstrlen) == 1
12653 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12654 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012655
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 " number of codepoints (Latin a + combining circumflex is two codepoints)
12658 " (comment from TM, solution from NW)
12659 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 elseif g:Align_xstrlen == 2
12662 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012663 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12664 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012665 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012666
Bram Moolenaar8d043172014-01-23 14:24:41 +010012667 elseif g:Align_xstrlen == 3
12668 " virtual length (counting, for instance, tabs as anything between 1 and
12669 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 " preceded by lam, one otherwise, etc.)
12671 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012672 let modkeep= &l:mod
12673 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012674 call setline(line("."),a:x)
12675 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012676 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012677 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012678 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012679
Bram Moolenaar446cb832008-06-24 21:56:24 +000012680 else
12681 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012682 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012685 return ret
12686endfun
12687
12688" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012689" s:ShellEscape: shellescape(), or special windows handling {{{2
12690fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012691 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012692 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12693 endif
12694 let f = a:0 > 0 ? a:1 : 0
12695 return shellescape(a:s, f)
12696endfun
12697
12698" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012699" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012700fun! s:TreeListMove(dir)
12701" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012702 let curline = getline('.')
12703 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12704 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12705 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12706 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12707 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12708 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12709" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12710" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12711" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12712" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12713" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12714 " COMBAK : need to handle when on a directory
12715 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012716 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012717 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012718 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012719 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012720" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012721 elseif a:dir == '[]' && nxtline != ''
12722 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012723" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12725 if nl != 0
12726 NetrwKeepj norm! k
12727 else
12728 NetrwKeepj norm! G
12729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012730" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012731 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012732 endif
12733
12734" call Dret("s:TreeListMove")
12735endfun
12736
12737" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012738" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12739" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12740" can't be called except via emenu. But due to locale, that menu line may not be called
12741" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12742fun! s:UpdateBuffersMenu()
12743" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012744 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012745 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012746 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012747 catch /^Vim\%((\a\+)\)\=:E/
12748 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012749 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012750 endtry
12751 endif
12752" call Dret("s:UpdateBuffersMenu")
12753endfun
12754
12755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012756" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012757" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012758fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012759" call Dfunc("s:UseBufWinVars()")
12760 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012761 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12762 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12763 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12764 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12765 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12766 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12767 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12768 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12769 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 +000012770" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012771endfun
12772
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012773" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012774" s:UserMaps: supports user-defined UserMaps {{{2
12775" * calls a user-supplied funcref(islocal,curdir)
12776" * interprets result
12777" See netrw#UserMaps()
12778fun! s:UserMaps(islocal,funcname)
12779" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12780
12781 if !exists("b:netrw_curdir")
12782 let b:netrw_curdir= getcwd()
12783 endif
12784 let Funcref = function(a:funcname)
12785 let result = Funcref(a:islocal)
12786
12787 if type(result) == 1
12788 " if result from user's funcref is a string...
12789" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12790 if result == "refresh"
12791" call Decho("refreshing display",'~'.expand("<slnum>"))
12792 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12793 elseif result != ""
12794" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12795 exe result
12796 endif
12797
12798 elseif type(result) == 3
12799 " if result from user's funcref is a List...
12800" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12801 for action in result
12802 if action == "refresh"
12803" call Decho("refreshing display",'~'.expand("<slnum>"))
12804 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12805 elseif action != ""
12806" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12807 exe action
12808 endif
12809 endfor
12810 endif
12811
12812" call Dret("s:UserMaps")
12813endfun
12814
Bram Moolenaar85850f32019-07-19 22:05:51 +020012815" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012816" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012817" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012818let &cpo= s:keepcpo
12819unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012820
Bram Moolenaar85850f32019-07-19 22:05:51 +020012821" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012822" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012823" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012824" vim:ts=8 fdm=marker