blob: b0dfd823c7f7965a5b22ef13d7165fe23d69c103 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Tom Benham4d618002024-10-31 10:47:23 +010034" 2024 Oct 31 by Vim Project: fix E874 when browsing remote dir (#15964)
Christian Brabandta063b222024-11-07 14:30:30 +010035" 2024 Nov 07 by Vim Project: use keeppatterns to prevent polluting the search history
Tom Benham64a536d2024-11-07 21:15:03 +010036" 2024 Nov 07 by Vim Project: fix a few issues with netrw tree listing (#15996)
Christian Brabandt5b63b232024-11-10 20:22:34 +010037" 2024 Nov 10 by Vim Project: directory symlink not resolved in tree view (#16020)
Konfekt460799d2024-11-14 21:42:27 +010038" 2024 Nov 14 by Vim Project: small fixes to netrw#BrowseX (#16056)
Christian Brabandtcacfccf2024-11-23 13:28:01 +010039" 2024 Nov 23 by Vim Project: update decompress defaults (#16104)
GuyBrushd7745ac2024-11-23 14:13:10 +010040" 2024 Nov 23 by Vim Project: fix powershell escaping issues (#16094)
Konfekteda923e2024-12-04 20:12:44 +010041" 2024 Dec 04 by Vim Project: do not detach for gvim (#16168)
Christian Brabandt92b36662024-12-08 09:52:37 +010042" 2024 Dec 08 by Vim Project: check the first arg of netrw_browsex_viewer for being executable (#16185)
Christian Brabandt5c42c772024-12-12 19:13:08 +010043" 2024 Dec 12 by Vim Project: do not pollute the search history (#16206)
Travis Sheltone34d0e32024-07-30 21:08:56 +020044" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010045" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000046" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010047" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000048" Permission is hereby granted to use and distribute this code,
49" with or without modifications, provided that this copyright
50" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000051" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000052" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000053" expressed or implied. By using this plugin, you agree that
54" in no event will the copyright holder be liable for any damages
55" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010056"
57" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
58" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
59"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020060"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000061"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000062" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000063" (James 1:22 RSV)
64" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000065" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000066if &cp || exists("g:loaded_netrw")
67 finish
68endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020069
70" Check that vim has patches that netrw requires.
71" Patches needed for v7.4: 1557, and 213.
72" (netrw will benefit from vim's having patch#656, too)
73let s:needspatches=[1557,213]
74if exists("s:needspatches")
75 for ptch in s:needspatches
76 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
77 if !exists("s:needpatch{ptch}")
78 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
79 endif
80 let s:needpatch{ptch}= 1
81 finish
82 endif
83 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020084endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020085
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010086let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000087
Bram Moolenaar1afcace2005-11-25 19:54:28 +000088let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010089setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020090"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010091"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010092"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000094" ======================
95" Netrw Variables: {{{1
96" ======================
97
Bram Moolenaar071d4272004-06-13 20:20:40 +000098" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020099" netrw#ErrorMsg: {{{2
100" 0=note = s:NOTE
101" 1=warning = s:WARNING
102" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100103" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
104" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
105" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100106" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200107fun! netrw#ErrorMsg(level,msg,errnum)
108" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
109
110 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200111" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112 return
113 endif
114
115 if a:level == 1
116 let level= "**warning** (netrw) "
117 elseif a:level == 2
118 let level= "**error** (netrw) "
119 else
120 let level= "**note** (netrw) "
121 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100122" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123
Damienb4d11642024-08-15 22:00:45 +0200124 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200125 " use popup window
126 if type(a:msg) == 3
127 let msg = [level]+a:msg
128 else
129 let msg= level.a:msg
130 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200131 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200132 let s:popuperr_text= ""
133 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 " (default) netrw creates a one-line window to show error/warning
135 " messages (reliably displayed)
136
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100137 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140
141 " getting messages out reliably is just plain difficult!
142 " This attempt splits the current window, creating a one line window.
143 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100144" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100146" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100148 if type(a:msg) == 3
149 for msg in a:msg
150 NetrwKeepj call setline(line("$")+1,level.msg)
151 endfor
152 else
153 NetrwKeepj call setline(line("$")+1,level.a:msg)
154 endif
155 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100157" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200158 bo 1split
159 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200160 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200161 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100162 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100163" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200164 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100165 if type(a:msg) == 3
166 for msg in a:msg
167 NetrwKeepj call setline(line("$")+1,level.msg)
168 endfor
169 else
170 NetrwKeepj call setline(line("$"),level.a:msg)
171 endif
172 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200173 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100174" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200175 if &fo !~ '[ta]'
176 syn clear
177 syn match netrwMesgNote "^\*\*note\*\*"
178 syn match netrwMesgWarning "^\*\*warning\*\*"
179 syn match netrwMesgError "^\*\*error\*\*"
180 hi link netrwMesgWarning WarningMsg
181 hi link netrwMesgError Error
182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100183" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200184 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200185
186 else
187 " (optional) netrw will show messages using echomsg. Even if the
188 " message doesn't appear, at least it'll be recallable via :messages
189" redraw!
190 if a:level == s:WARNING
191 echohl WarningMsg
192 elseif a:level == s:ERROR
193 echohl Error
194 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100195
196 if type(a:msg) == 3
197 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100198 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100199 endfor
200 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100201 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100202 endif
203
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100204" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200205 echohl None
206 endif
207
208" call Dret("netrw#ErrorMsg")
209endfun
210
211" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100212" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100213" Loosely, varname = value.
214fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100215" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100216 if !exists(a:varname)
217 if type(a:value) == 0
218 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200219 elseif type(a:value) == 1 && a:value =~ '^[{[]'
220 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100221 elseif type(a:value) == 1
222 exe "let ".a:varname."="."'".a:value."'"
223 else
224 exe "let ".a:varname."=".a:value
225 endif
226 endif
227endfun
228
229" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000230" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200231call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000232if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100233 call s:NetrwInit("s:THINLIST",0)
234 call s:NetrwInit("s:LONGLIST",1)
235 call s:NetrwInit("s:WIDELIST",2)
236 call s:NetrwInit("s:TREELIST",3)
237 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000238endif
239
Damien7c754112024-08-15 21:58:57 +0200240let s:NOTE = 0
241let s:WARNING = 1
242let s:ERROR = 2
243call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
244
Bram Moolenaar9964e462007-05-05 17:54:07 +0000245" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200246" Default option values: {{{2
247let g:netrw_localcopycmdopt = ""
248let g:netrw_localcopydircmdopt = ""
249let g:netrw_localmkdiropt = ""
250let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200251
252" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000253" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200254if exists("*popup_atcursor")
255\ && has("syntax")
256\ && exists("g:syntax_on")
257\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200258 call s:NetrwInit("g:netrw_use_errorwindow",2)
259else
260 call s:NetrwInit("g:netrw_use_errorwindow",1)
261endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200262
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000263if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100264 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000265 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100266 elseif executable("curl")
267 let g:netrw_dav_cmd = "curl"
268 else
269 let g:netrw_dav_cmd = ""
270 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000272if !exists("g:netrw_fetch_cmd")
273 if executable("fetch")
274 let g:netrw_fetch_cmd = "fetch -o"
275 else
276 let g:netrw_fetch_cmd = ""
277 endif
278endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100279if !exists("g:netrw_file_cmd")
280 if executable("elinks")
281 call s:NetrwInit("g:netrw_file_cmd","elinks")
282 elseif executable("links")
283 call s:NetrwInit("g:netrw_file_cmd","links")
284 endif
285endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000286if !exists("g:netrw_ftp_cmd")
287 let g:netrw_ftp_cmd = "ftp"
288endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200289let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200290if !exists("g:netrw_ftp_options")
291 let g:netrw_ftp_options= "-i -n"
292endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000293if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100294 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100295 let g:netrw_http_cmd = "wget"
296 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100297 elseif executable("curl")
298 let g:netrw_http_cmd = "curl"
299 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200300 elseif executable("elinks")
301 let g:netrw_http_cmd = "elinks"
302 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000303 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100304 let g:netrw_http_cmd = "fetch"
305 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200306 elseif executable("links")
307 let g:netrw_http_cmd = "links"
308 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000309 else
310 let g:netrw_http_cmd = ""
311 endif
312endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100313call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100314call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100315call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
316call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200317call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200318if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200319 if executable("scp")
320 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
321 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200322 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200323 else
324 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
325 endif
326endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100327call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
328call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000329
Nir Lichtman1e34b952024-05-08 19:19:34 +0200330if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000331 \ && exists("g:netrw_use_nt_rcp")
332 \ && g:netrw_use_nt_rcp
333 \ && executable( $SystemRoot .'/system32/rcp.exe')
334 let s:netrw_has_nt_rcp = 1
335 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000336else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000337 let s:netrw_has_nt_rcp = 0
338 let s:netrw_rcpmode = ''
339endif
340
341" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000342" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000343" Cygwin Detection ------- {{{3
344if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200345 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
346 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000347 else
348 let g:netrw_cygwin= 0
349 endif
350endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000351" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100352call s:NetrwInit("g:netrw_alto" , &sb)
353call s:NetrwInit("g:netrw_altv" , &spr)
354call s:NetrwInit("g:netrw_banner" , 1)
355call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200356call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200358call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100359call s:NetrwInit("g:netrw_compress" , "gzip")
360call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200361if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
362 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
363 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000364endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200365call s:NetrwInit("g:netrw_cursor" , 2)
366let s:netrw_usercul = &cursorline
367let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200368"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100369call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000370" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200371call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200372call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Christian Brabandtcacfccf2024-11-23 13:28:01 +0100373let s:xz_opt = has('unix') ? "XZ_OPT=-T0" :
374 \ (has("win32") && &shell =~? '\vcmd(\.exe)?$' ?
375 \ "setx XZ_OPT=-T0 &&" : "")
376call s:NetrwInit("g:netrw_decompress ", "{"
377 \ .."'.lz4': 'lz4 -d',"
378 \ .."'.lzo': 'lzop -d',"
379 \ .."'.lz': 'lzip -dk',"
380 \ .."'.7z': '7za x',"
381 \ .."'.001': '7za x',"
382 \ .."'.zip': 'unzip',"
383 \ .."'.bz': 'bunzip2 -k',"
384 \ .."'.bz2': 'bunzip2 -k',"
385 \ .."'.gz': 'gunzip -k',"
386 \ .."'.lzma': 'unlzma -T0 -k',"
387 \ .."'.xz': 'unxz -T0 -k',"
388 \ .."'.zst': 'zstd -T0 -d',"
389 \ .."'.Z': 'uncompress -k',"
390 \ .."'.tar': 'tar -xvf',"
391 \ .."'.tar.bz': 'tar -xvjf',"
392 \ .."'.tar.bz2': 'tar -xvjf',"
393 \ .."'.tbz': 'tar -xvjf',"
394 \ .."'.tbz2': 'tar -xvjf',"
395 \ .."'.tar.gz': 'tar -xvzf',"
396 \ .."'.tgz': 'tar -xvzf',"
397 \ .."'.tar.lzma': '"..s:xz_opt.." tar -xvf --lzma',"
398 \ .."'.tlz': '"..s:xz_opt.." tar -xvf --lzma',"
399 \ .."'.tar.xz': '"..s:xz_opt.." tar -xvfJ',"
400 \ .."'.txz': '"..s:xz_opt.." tar -xvfJ',"
401 \ .."'.tar.zst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
402 \ .."'.tzst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
403 \ .."'.rar': '"..(executable("unrar")?"unrar x -ad":"rar x -ad").."'"
404 \ .."}")
405unlet s:xz_opt
Bram Moolenaar5c736222010-01-06 20:54:52 +0100406call s:NetrwInit("g:netrw_dirhistmax" , 10)
407call s:NetrwInit("g:netrw_fastbrowse" , 1)
408call 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 +0000409if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000410 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
411 let g:netrw_ftp_list_cmd = "ls -lF"
412 let g:netrw_ftp_timelist_cmd = "ls -tlF"
413 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000414 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000415 let g:netrw_ftp_list_cmd = "dir"
416 let g:netrw_ftp_timelist_cmd = "dir"
417 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000418 endif
419endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100420call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000421" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100422call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000423if !exists("g:netrw_ignorenetrc")
424 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
425 let g:netrw_ignorenetrc= 1
426 else
427 let g:netrw_ignorenetrc= 0
428 endif
429endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100430call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000431if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000432 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 if exists("g:netrw_list_cmd_options")
434 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
435 else
436 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
437 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000438 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200439 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100440 if exists("g:netrw_list_cmd_options")
441 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
442 else
443 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
444 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000445 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100446" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000447 let g:netrw_list_cmd= ""
448 endif
449endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100450call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000451" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200453 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200454 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
455endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100456if !exists("g:netrw_localcmdshell")
457 let g:netrw_localcmdshell= ""
458endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000459if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200460 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000461 if g:netrw_cygwin
462 let g:netrw_localcopycmd= "cp"
463 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000464 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200465 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000466 endif
467 elseif has("unix") || has("macunix")
468 let g:netrw_localcopycmd= "cp"
469 else
470 let g:netrw_localcopycmd= ""
471 endif
472endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100473if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200474 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100475 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200476 let g:netrw_localcopydircmd = "cp"
477 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100478 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000479 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200480 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100481 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200482 elseif has("unix")
483 let g:netrw_localcopydircmd = "cp"
484 let g:netrw_localcopydircmdopt= " -R"
485 elseif has("macunix")
486 let g:netrw_localcopydircmd = "cp"
487 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100488 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200489 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100490 endif
491endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200492if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100493 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200494 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
495endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200496if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200497 if g:netrw_cygwin
498 call s:NetrwInit("g:netrw_localmkdir","mkdir")
499 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000500 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200501 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200502 endif
503else
504 call s:NetrwInit("g:netrw_localmkdir","mkdir")
505endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200506call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200507if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200508 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200509 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
510endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000511if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200512 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000513 if g:netrw_cygwin
514 let g:netrw_localmovecmd= "mv"
515 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000516 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200517 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000518 endif
519 elseif has("unix") || has("macunix")
520 let g:netrw_localmovecmd= "mv"
521 else
522 let g:netrw_localmovecmd= ""
523 endif
524endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100525" following serves as an example for how to insert a version&patch specific test
526"if v:version < 704 || (v:version == 704 && !has("patch1107"))
527"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
529" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000530if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000531 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000532endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000533if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000534 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
535endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000536" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100537call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
538call s:NetrwInit("g:netrw_maxfilenamelen", 32)
539call s:NetrwInit("g:netrw_menu" , 1)
540call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200541call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:netrw_retmap" , 0)
543if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
544 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200545elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
547else
548 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000549endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550call s:NetrwInit("g:netrw_preview" , 0)
551call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100552call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100553call s:NetrwInit("g:netrw_sshport" , "-p")
554call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
555call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
556call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100557call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
558" Default values - q-s ---------- {{{3
559call s:NetrwInit("g:netrw_quickhelp",0)
560let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100561 \ "(create new) %:file d:directory",
562 \ "(windows split&open) o:horz v:vert p:preview",
563 \ "i:style qf:file info O:obtain r:reverse",
564 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
565 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
566 \ "(history) qb:list u:go up U:go down",
567 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100568" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
569call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100570if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
571 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
572else
573 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
574endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100575call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
576call s:NetrwInit("g:netrw_sort_options" , "")
577call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000578if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100579 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200580 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100581 else
582 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000583 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000584endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100585call s:NetrwInit("g:netrw_special_syntax" , 0)
586call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100587call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100588call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000589" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100590call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200591if !exists("g:netrw_xstrlen")
592 if exists("g:Align_xstrlen")
593 let g:netrw_xstrlen= g:Align_xstrlen
594 elseif exists("g:drawit_xstrlen")
595 let g:netrw_xstrlen= g:drawit_xstrlen
596 elseif &enc == "latin1" || !has("multi_byte")
597 let g:netrw_xstrlen= 0
598 else
599 let g:netrw_xstrlen= 1
600 endif
601endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100602call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200603call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100604call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200605if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000606" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000607" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100608call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200609if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200610 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200611else
Bram Moolenaarff034192013-04-24 18:51:19 +0200612 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200613endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200614call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100615call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
616call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100617if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100618 let s:treedepthstring= "│ "
619else
620 let s:treedepthstring= "| "
621endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200622call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000623
624" BufEnter event ignored by decho when following variable is true
625" Has a side effect that doau BufReadPost doesn't work, so
626" files read by network transfer aren't appropriately highlighted.
627"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628
Bram Moolenaaradc21822011-04-01 18:03:16 +0200629" ======================
630" Netrw Initialization: {{{1
631" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200632if 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 +0100633" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100634 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200635" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100636 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100637 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
638 au VimEnter * let s:initbeval= &beval
639"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100640" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
641" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
642" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
643" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
644" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
645" 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 +0200646endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200647au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200648
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200649if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100650 com! -nargs=* NetrwKeepj keepj <args>
651else
652 let g:netrw_keepj= ""
653 com! -nargs=* NetrwKeepj <args>
654endif
655
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000656" ==============================
657" Netrw Utility Functions: {{{1
658" ==============================
659
Bram Moolenaaradc21822011-04-01 18:03:16 +0200660" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100661" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100662if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100663" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100664 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100665 if &ft != "netrw"
666 return ""
667 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200668 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
669 " popup error window is still showing
670 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
671 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
672 " text under mouse hasn't changed; only close window when it changes
673 call popup_close(s:popuperr_id)
674 unlet s:popuperr_text
675 else
676 let s:popuperr_text= v:beval_text
677 endif
678 let mesg= ""
679 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 +0100680 let mesg= ""
681 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
682 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
683 elseif getline(v:beval_lnum) =~ '^"\s*/'
684 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
685 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100686 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100687 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
688 let mesg = "S: edit sorting sequence"
689 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
690 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
691 elseif v:beval_text == "Quick" || v:beval_text == "Help"
692 let mesg = "Help: press <F1>"
693 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
694 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
695 else
696 let mesg= ""
697 endif
698 return mesg
699 endfun
700"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100701" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
702" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
703" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
704" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
705" 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 +0200706endif
707
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200709" netrw#Explore: launch the local browser in the directory of the current file {{{2
710" indx: == -1: Nexplore
711" == -2: Pexplore
712" == +: this is overloaded:
713" * If Nexplore/Pexplore is in use, then this refers to the
714" indx'th item in the w:netrw_explore_list[] of items which
715" matched the */pattern **/pattern *//pattern **//pattern
716" * If Hexplore or Vexplore, then this will override
717" g:netrw_winsize to specify the qty of rows or columns the
718" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100719" 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 +0200720" dosplit==1: the window will be split before running the local browser
721" style == 0: Explore style == 1: Explore!
722" == 2: Hexplore style == 3: Hexplore!
723" == 4: Vexplore style == 5: Vexplore!
724" == 6: Texplore
725fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200726 if !exists("b:netrw_curdir")
727 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100729
730 " record current file for Rexplore's benefit
731 if &ft != "netrw"
732 let w:netrw_rexfile= expand("%:p")
733 endif
734
735 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let curdir = simplify(b:netrw_curdir)
737 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200738 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200739 let curdir= substitute(curdir,'\','/','g')
740 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100741
742 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
743 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
744 " try Explore again.
745 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100746 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200747 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
748 if a1 != a:1
749 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
750 return
751 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100752 endif
753 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200756 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100757" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100758 sil! let keepregstar = @*
759 sil! let keepregplus = @+
760 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 sil! let keepregslash= @/
762
Bram Moolenaar8d043172014-01-23 14:24:41 +0100763 " if dosplit
764 " -or- file has been modified AND file not hidden when abandoned
765 " -or- Texplore used
766 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 call s:SaveWinVars()
768 let winsz= g:netrw_winsize
769 if a:indx > 0
770 let winsz= a:indx
771 endif
772
773 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200775 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200776 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200777
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200778 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200780 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200781 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200782
783 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200785 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200786 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200787
788 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200790 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200791 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200792
793 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200795 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200796 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200797
798 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200800 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200801 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200802
803 elseif a:style == 6 " Texplore
804 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 exe "keepalt tabnew ".fnameescape(curdir)
806 call s:RestoreBufVars()
807 endif
808 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100810 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200811
812 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
817 if dirname !~ '/$'
818 let dirname= dirname."/"
819 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200822 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 let dirname= a:1
826 endif
827 else
828 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 return
831 endif
832
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 if dirname =~ '\.\./\=$'
834 let dirname= simplify(fnamemodify(dirname,':p:h'))
835 elseif dirname =~ '\.\.' || dirname == '.'
836 let dirname= simplify(fnamemodify(dirname,':p'))
837 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200838
839 if dirname =~ '^\*//'
840 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
842 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200843 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
844
845 elseif dirname =~ '^\*\*//'
846 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200847 let pattern= substitute(dirname,'^\*\*//','','')
848 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname =~ '/\*\*/'
851 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200852 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200853 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854 let b:netrw_curdir = prefixdir
855 else
856 let b:netrw_curdir= getcwd().'/'.prefixdir
857 endif
858 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
859 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200860
861 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200862 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200864
865 elseif dirname=~ '^\*\*/'
866 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
867 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200868
869 else
870 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 endif
872
873 if starpat == 0 && a:indx >= 0
874 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 if dirname == ""
876 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200878 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200879 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200880 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200881 if dirname == ""
882 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200883 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100885 " depending on whether backslashes have been converted to forward slashes by earlier code).
886 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200887 let dirname= b:netrw_curdir."/".dirname
888 endif
889 elseif dirname !~ '^/'
890 let dirname= b:netrw_curdir."/".dirname
891 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200893 endif
894 if exists("w:netrw_bannercnt")
895 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
896 " If one wants to return the same place in the netrw window, use :Rex instead.
897 exe w:netrw_bannercnt
898 endif
899
Bram Moolenaarff034192013-04-24 18:51:19 +0200900
901 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
902 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
903 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
904 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
905 elseif a:indx <= 0
906 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200907 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200908 let s:didstarstar= 1
909 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
910 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
911 endif
912
913 if has("path_extra")
Bram 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 Moolenaarff034192013-04-24 18:51:19 +0200919
920 if indx == -1
921 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200922 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100923 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 +0200924 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100925 if @* != keepregstar | sil! let @* = keepregstar | endif
926 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100927 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200928 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200929 return
930 endif
931 let indx= w:netrw_explore_indx
932 if indx < 0 | let indx= 0 | endif
933 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
934 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
936 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200937 endwhile
938 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200939
940 elseif indx == -2
941 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200942 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100943 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 +0200944 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100945 if @* != keepregstar | sil! let @* = keepregstar | endif
946 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100947 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 return
950 endif
951 let indx= w:netrw_explore_indx
952 if indx < 0 | let indx= 0 | endif
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
954 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 while indx >= 0 && curfile == w:netrw_explore_list[indx]
956 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200957 endwhile
958 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200959
960 else
961 " Explore -- initialize
962 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100963 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200964 let w:netrw_explore_indx= 0
965 if !exists("b:netrw_curdir")
966 let b:netrw_curdir= getcwd()
967 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200968
969 " switch on starpat to build the w:netrw_explore_list of files
970 if starpat == 1
971 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100973 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 catch /^Vim\%((\a\+)\)\=:E480/
975 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 return
977 endtry
978 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
979 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
980
981 elseif starpat == 2
982 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100984 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 catch /^Vim\%((\a\+)\)\=:E480/
986 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
987 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200988 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100989 if @* != keepregstar | sil! let @* = keepregstar | endif
990 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100991 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 return
994 endtry
995 let s:netrw_curdir = b:netrw_curdir
996 let w:netrw_explore_list = getqflist()
997 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
998 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
999
1000 elseif starpat == 3
1001 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 let filepat= substitute(dirname,'^\*/','','')
1003 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +02001004 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1005 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1006
1007 elseif starpat == 4
1008 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1010 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1011 endif " switch on starpat to build w:netrw_explore_list
1012
1013 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +02001014
1015 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001016 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001017 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001018 if @* != keepregstar | sil! let @* = keepregstar | endif
1019 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001020 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001021 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 return
1023 endif
1024 endif " if indx ... endif
1025
1026 " NetrwStatusLine support - for exploring support
1027 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +02001028
1029 " wrap the indx around, but issue a note
1030 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +02001031 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1032 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001033 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 endif
1035
1036 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +02001037 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001038
Bram Moolenaarff034192013-04-24 18:51:19 +02001039 call netrw#LocalBrowseCheck(newdir)
1040 if !exists("w:netrw_liststyle")
1041 let w:netrw_liststyle= g:netrw_liststyle
1042 endif
1043 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001044 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001045 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001046 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001047 endif
1048 let w:netrw_explore_mtchcnt = indx + 1
1049 let w:netrw_explore_bufnr = bufnr("%")
1050 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001051 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001052
1053 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001054 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001055 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 +02001056 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001057 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001058 if @* != keepregstar | sil! let @* = keepregstar | endif
1059 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001060 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001061 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 return
1063 endif
1064
1065 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001066 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1067 sil! unlet w:netrw_treedict
1068 sil! unlet w:netrw_treetop
1069 endif
1070 let newdir= dirname
1071 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001072 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 else
Tom Benham64a536d2024-11-07 21:15:03 +01001074 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076 endif
1077
1078 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001081 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 let s:explore_prvdir = b:netrw_curdir
1083 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001084 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 if b:netrw_curdir !~ '/$'
1086 let dirlen= dirlen + 1
1087 endif
1088 let prvfname= ""
1089 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 if fname =~ '^'.b:netrw_curdir
1091 if s:explore_match == ""
1092 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1093 else
1094 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1095 endif
1096 elseif fname !~ '^/' && fname != prvfname
1097 if s:explore_match == ""
1098 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1099 else
1100 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1101 endif
1102 endif
1103 let prvfname= fname
1104 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001105 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1106 exe "2match netrwMarkFile /".s:explore_match."/"
1107 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 endif
1109 echo "<s-up>==Pexplore <s-down>==Nexplore"
1110 else
1111 2match none
1112 if exists("s:explore_match") | unlet s:explore_match | endif
1113 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 endif
1115
Bram Moolenaara6878372014-03-22 21:02:50 +01001116 " since Explore may be used to initialize netrw's browser,
1117 " there's no danger of a late FocusGained event on initialization.
1118 " Consequently, set s:netrw_events to 2.
1119 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001120 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001121 if @* != keepregstar | sil! let @* = keepregstar | endif
1122 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001123 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001125endfun
1126
1127" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001128" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001129" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1130" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1131" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1132" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1133" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001134fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001135" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001136 let curwin= winnr()
1137
Bram Moolenaara6878372014-03-22 21:02:50 +01001138 if a:0 > 0 && a:1 != ""
1139 " if a netrw window is already on the left-side of the tab
1140 " and a directory has been specified, explore with that
1141 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001142 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001143 exe "1wincmd w"
1144 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001145 exe "Explore ".fnameescape(a1)
1146 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001147 let s:lexplore_win= curwin
1148 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001149 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001150 unlet t:netrw_lexposn
1151 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001152 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001153 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001154 exe curwin."wincmd w"
1155 else
1156 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001157 endif
1158
Bram Moolenaar8d043172014-01-23 14:24:41 +01001159 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001160 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001161 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001162 else
1163 let lexwinnr= 0
1164 endif
1165
1166 if lexwinnr > 0
1167 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001168 exe lexwinnr."wincmd w"
1169 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001170 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001171 close
1172 if lexwinnr < curwin
1173 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001174 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001175 if lexwinnr != curwin
1176 exe curwin."wincmd w"
1177 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001178 unlet t:netrw_lexbufnr
1179
1180 else
1181 " open netrw explorer window
1182 exe "1wincmd w"
1183 let keep_altv = g:netrw_altv
1184 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185 if a:count != 0
1186 let netrw_winsize = g:netrw_winsize
1187 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001188 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1191 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001192 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001194 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001195 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001196 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001197 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 endif
1199 if a:count != 0
1200 let g:netrw_winsize = netrw_winsize
1201 endif
1202 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001203 let g:netrw_altv = keep_altv
1204 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001205 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1206 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001207 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001208 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001210 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 unlet t:netrw_lexposn
1212 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001213 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214
1215 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 if a:rightside
1218 let g:netrw_chgwin= 1
1219 else
1220 let g:netrw_chgwin= 2
1221 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001222 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223
Bram Moolenaar8d043172014-01-23 14:24:41 +01001224endfun
1225
1226" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001227" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001228" supports :NetrwClean -- remove netrw from first directory on runtimepath
1229" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001230fun! netrw#Clean(sys)
1231" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001232
1233 if a:sys
1234 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1235 else
1236 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1237 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001238" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001239 let diddel= 0
1240 let diddir= ""
1241
1242 if choice == 1
1243 for dir in split(&rtp,',')
1244 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001245" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001246 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1247 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1248 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1249 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1250 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1251 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 +00001252 let diddir= dir
1253 let diddel= diddel + 1
1254 if !a:sys|break|endif
1255 endif
1256 endfor
1257 endif
1258
1259 echohl WarningMsg
1260 if diddel == 0
1261 echomsg "netrw is either not installed or not removable"
1262 elseif diddel == 1
1263 echomsg "removed one copy of netrw from <".diddir.">"
1264 else
1265 echomsg "removed ".diddel." copies of netrw"
1266 endif
1267 echohl None
1268
Bram Moolenaara6878372014-03-22 21:02:50 +01001269" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001270endfun
1271
Bram Moolenaar5c736222010-01-06 20:54:52 +01001272" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001273" netrw#MakeTgt: make a target out of the directory name provided {{{2
1274fun! netrw#MakeTgt(dname)
1275" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1276 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001277 let svpos = winsaveview()
1278" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001279 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1280" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001281 if s:netrwmftgt_islocal
1282 let netrwmftgt= simplify(a:dname)
1283 else
1284 let netrwmftgt= a:dname
1285 endif
1286 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1287 " re-selected target, so just clear it
1288 unlet s:netrwmftgt s:netrwmftgt_islocal
1289 else
1290 let s:netrwmftgt= netrwmftgt
1291 endif
1292 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001293 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001294 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001295" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1296 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001297" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001298endfun
1299
Bram Moolenaara6878372014-03-22 21:02:50 +01001300" ---------------------------------------------------------------------
1301" netrw#Obtain: {{{2
1302" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001303" islocal=0 obtain from remote source
1304" =1 obtain from local source
1305" fname : a filename or a list of filenames
1306" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001307fun! netrw#Obtain(islocal,fname,...)
1308" 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 +02001309 " NetrwStatusLine support - for obtaining support
1310
1311 if type(a:fname) == 1
1312 let fnamelist= [ a:fname ]
1313 elseif type(a:fname) == 3
1314 let fnamelist= a:fname
1315 else
1316 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 +01001317" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001318 return
1319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001320" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001321 if a:0 > 0
1322 let tgtdir= a:1
1323 else
1324 let tgtdir= getcwd()
1325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001327
1328 if exists("b:netrw_islocal") && b:netrw_islocal
1329 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001330" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001331 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1332 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001333 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001334 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001335" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001336 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001337" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001338 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001339 if v:shell_error != 0
1340 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 +01001341" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001342 return
1343 endif
1344 endfor
1345 else
1346 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001347" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1348 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1349" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001350 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001351 if v:shell_error != 0
1352 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 +01001353" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001354 return
1355 endif
1356 endif
1357 elseif !exists("b:netrw_curdir")
1358 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1359 else
1360 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1361 endif
1362
1363 else
1364 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001365" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001366 if type(a:fname) == 1
1367 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1368 endif
1369 call s:NetrwMethod(b:netrw_curdir)
1370
1371 if b:netrw_method == 4
1372 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001373" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001374 if exists("g:netrw_port") && g:netrw_port != ""
1375 let useport= " ".g:netrw_scpport." ".g:netrw_port
1376 else
1377 let useport= ""
1378 endif
1379 if b:netrw_fname =~ '/'
1380 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1381 else
1382 let path= ""
1383 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001384 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001385 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 +02001386
1387 elseif b:netrw_method == 2
1388 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001389" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001390 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001391 let tmpbufnr= bufnr("%")
1392 setl ff=unix
1393 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001394 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001395" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 endif
1397
1398 if exists("b:netrw_fname") && b:netrw_fname != ""
1399 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 endif
1402
1403 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001404 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 endif
1407 for fname in fnamelist
1408 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 endfor
1411 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412 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 +02001413 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 endif
1416 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1417 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1418 let debugkeep= &debug
1419 setl debug=msg
1420 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1421 let &debug= debugkeep
1422 endif
1423
1424 elseif b:netrw_method == 3
1425 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001426" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001427 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 let tmpbufnr= bufnr("%")
1429 setl ff=unix
1430
1431 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001432 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001433" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001435 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001436" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 endif
1438
1439 if exists("g:netrw_uid") && g:netrw_uid != ""
1440 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001441 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001444 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001445 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001447 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001448 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001449" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 endif
1451 endif
1452
1453 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001454 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001455" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001456 endif
1457
1458 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001459 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001460" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001461 endif
1462
1463 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001464 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001465" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001466 endif
1467
1468 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001469 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 endif
1472 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001476
1477 " perform ftp:
1478 " -i : turns off interactive prompting from ftp
1479 " -n unix : DON'T use <.netrc>, even though it exists
1480 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001481 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1482 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001483 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1485 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001488 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endif
1490 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001491
1492 elseif b:netrw_method == 9
1493 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001495 if a:fname =~ '/'
1496 let localfile= substitute(a:fname,'^.*/','','')
1497 else
1498 let localfile= a:fname
1499 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500 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 +02001501
Bram Moolenaarff034192013-04-24 18:51:19 +02001502 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001503 " probably a badly formed url; protocol not recognized
1504" call Dret("netrw#Obtain : unsupported method")
1505 return
1506
1507 else
1508 " protocol recognized but not supported for Obtain (yet?)
1509 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001511 endif
1512" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 return
1514 endif
1515
1516 " restore status line
1517 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001519 endif
1520
1521 endif
1522
1523 " cleanup
1524 if exists("tmpbufnr")
1525 if bufnr("%") != tmpbufnr
1526 exe tmpbufnr."bw!"
1527 else
1528 q!
1529 endif
1530 endif
1531
Bram Moolenaara6878372014-03-22 21:02:50 +01001532" call Dret("netrw#Obtain")
1533endfun
1534
1535" ---------------------------------------------------------------------
1536" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1537fun! netrw#Nread(mode,fname)
1538" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001539 let svpos= winsaveview()
1540" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001541 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001542" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1543 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001544
1545 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1546 if exists("w:netrw_bannercnt")
1547 " start with cursor just after the banner
1548 exe w:netrw_bannercnt
1549 endif
1550 endif
1551" call Dret("netrw#Nread")
1552endfun
1553
1554" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001555" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1556" Options get restored by s:NetrwOptionsRestore()
1557"
1558" Option handling:
1559" * save user's options (s:NetrwOptionsSave)
1560" * set netrw-safe options (s:NetrwOptionsSafe)
1561" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1562" * restore user's options (s:netrwOPtionsRestore)
1563" - restore a user option when != safe option (s:NetrwRestoreSetting)
1564" vt: (variable type) normally its either "w:" or "s:"
1565fun! s:NetrwOptionsSave(vt)
1566" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1567" 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 +02001568" 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>"))
1569" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001570
1571 if !exists("{a:vt}netrw_optionsave")
1572 let {a:vt}netrw_optionsave= 1
1573 else
1574" call Dret("s:NetrwOptionsSave : options already saved")
1575 return
1576 endif
1577" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1578
1579 " Save current settings and current directory
1580" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1581 let s:yykeep = @@
1582 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1583 let {a:vt}netrw_aikeep = &l:ai
1584 let {a:vt}netrw_awkeep = &l:aw
1585 let {a:vt}netrw_bhkeep = &l:bh
1586 let {a:vt}netrw_blkeep = &l:bl
1587 let {a:vt}netrw_btkeep = &l:bt
1588 let {a:vt}netrw_bombkeep = &l:bomb
1589 let {a:vt}netrw_cedit = &cedit
1590 let {a:vt}netrw_cikeep = &l:ci
1591 let {a:vt}netrw_cinkeep = &l:cin
1592 let {a:vt}netrw_cinokeep = &l:cino
1593 let {a:vt}netrw_comkeep = &l:com
1594 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001595 let {a:vt}netrw_cuckeep = &l:cuc
1596 let {a:vt}netrw_culkeep = &l:cul
1597" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001598 let {a:vt}netrw_diffkeep = &l:diff
1599 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001600 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1601 let {a:vt}netrw_ffkeep = &l:ff
1602 endif
1603 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1604 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001605 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001606 let {a:vt}netrw_hidkeep = &l:hidden
1607 let {a:vt}netrw_imkeep = &l:im
1608 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001609 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001610 let {a:vt}netrw_lskeep = &l:ls
1611 let {a:vt}netrw_makeep = &l:ma
1612 let {a:vt}netrw_magickeep = &l:magic
1613 let {a:vt}netrw_modkeep = &l:mod
1614 let {a:vt}netrw_nukeep = &l:nu
1615 let {a:vt}netrw_rnukeep = &l:rnu
1616 let {a:vt}netrw_repkeep = &l:report
1617 let {a:vt}netrw_rokeep = &l:ro
1618 let {a:vt}netrw_selkeep = &l:sel
1619 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001620 if !g:netrw_use_noswf
1621 let {a:vt}netrw_swfkeep = &l:swf
1622 endif
1623 let {a:vt}netrw_tskeep = &l:ts
1624 let {a:vt}netrw_twkeep = &l:tw " textwidth
1625 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1626 let {a:vt}netrw_wrapkeep = &l:wrap
1627 let {a:vt}netrw_writekeep = &l:write
1628
1629 " save a few selected netrw-related variables
1630" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1631 if g:netrw_keepdir
1632 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001633" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001634 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001635 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001636 sil! let {a:vt}netrw_starkeep = @*
1637 sil! let {a:vt}netrw_pluskeep = @+
1638 endif
1639 sil! let {a:vt}netrw_slashkeep= @/
1640
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001641" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +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,'~'.expand("<slnum>"))
1643" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1644endfun
1645
1646" ---------------------------------------------------------------------
1647" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1648" Use s:NetrwSaveOptions() to save user settings
1649" Use s:NetrwOptionsRestore() to restore user settings
1650fun! s:NetrwOptionsSafe(islocal)
1651" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1652" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1653" 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>"))
1654 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1655 call s:NetrwSetSafeSetting("&l:ai",0)
1656 call s:NetrwSetSafeSetting("&l:aw",0)
1657 call s:NetrwSetSafeSetting("&l:bl",0)
1658 call s:NetrwSetSafeSetting("&l:bomb",0)
1659 if a:islocal
1660 call s:NetrwSetSafeSetting("&l:bt","nofile")
1661 else
1662 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1663 endif
1664 call s:NetrwSetSafeSetting("&l:ci",0)
1665 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001666 if g:netrw_fastbrowse > a:islocal
1667 call s:NetrwSetSafeSetting("&l:bh","hide")
1668 else
1669 call s:NetrwSetSafeSetting("&l:bh","delete")
1670 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001671 call s:NetrwSetSafeSetting("&l:cino","")
1672 call s:NetrwSetSafeSetting("&l:com","")
1673 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1674 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1675 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001676 if &go =~ 'a' | set go-=a | endif
1677 if &go =~ 'A' | set go-=A | endif
1678 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 call s:NetrwSetSafeSetting("&l:hid",0)
1680 call s:NetrwSetSafeSetting("&l:im",0)
1681 setl isk+=@ isk+=* isk+=/
1682 call s:NetrwSetSafeSetting("&l:magic",1)
1683 if g:netrw_use_noswf
1684 call s:NetrwSetSafeSetting("swf",0)
1685 endif
1686 call s:NetrwSetSafeSetting("&l:report",10000)
1687 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1688 call s:NetrwSetSafeSetting("&l:spell",0)
1689 call s:NetrwSetSafeSetting("&l:tw",0)
1690 call s:NetrwSetSafeSetting("&l:wig","")
1691 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001692
1693 " set up cuc and cul based on g:netrw_cursor and listing style
1694 " COMBAK -- cuc cul related
1695 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696
1697 " allow the user to override safe options
1698" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1699 if &ft == "netrw"
1700" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1701 keepalt NetrwKeepj doau FileType netrw
1702 endif
1703
1704" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1705" 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>"))
1706" call Dret("s:NetrwOptionsSafe")
1707endfun
1708
1709" ---------------------------------------------------------------------
1710" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1711fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001712 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001713 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1714 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1715 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001716 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001717 else
1718 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001719 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001720 return
1721 endif
1722 unlet {a:vt}netrw_optionsave
1723
1724 if exists("+acd")
1725 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001726 let curdir = getcwd()
1727 let &l:acd = {a:vt}netrw_acdkeep
1728 unlet {a:vt}netrw_acdkeep
1729 if &l:acd
1730 call s:NetrwLcd(curdir)
1731 endif
1732 endif
1733 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001734 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1735 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1736 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1737 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1738 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1739 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1740 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1741 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1742 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1743 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1744 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1745 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1746 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1747 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1748 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001749 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001750 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1751 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001752 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001753 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001754 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1755 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001756 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001757 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1758 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001759 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001760 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1761 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001762 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1763 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1764 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1765 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001766 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001767 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1768 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1769 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001770 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1771 call s:NetrwRestoreSetting("s:yykeep","@@")
1772 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1773 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1774 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1775 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1776
Bram Moolenaara6878372014-03-22 21:02:50 +01001777 if exists("{a:vt}netrw_swfkeep")
1778 if &directory == ""
1779 " user hasn't specified a swapfile directory;
1780 " netrw will temporarily set the swapfile directory
1781 " to the current directory as returned by getcwd().
1782 let &l:directory= getcwd()
1783 sil! let &l:swf = {a:vt}netrw_swfkeep
1784 setl directory=
1785 unlet {a:vt}netrw_swfkeep
1786 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001787 if !g:netrw_use_noswf
1788 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1789 sil! let &l:swf= {a:vt}netrw_swfkeep
1790 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001791 unlet {a:vt}netrw_swfkeep
1792 endif
1793 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001794 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001795 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1796 if exists("{a:vt}netrw_dirkeep")
1797 call s:NetrwLcd(dirkeep)
1798 unlet {a:vt}netrw_dirkeep
1799 endif
1800 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001801 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001802 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1803 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001804 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001805 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001806
Bram Moolenaara6878372014-03-22 21:02:50 +01001807 " Moved the filetype detect here from NetrwGetFile() because remote files
1808 " were having their filetype detect-generated settings overwritten by
1809 " NetrwOptionRestore.
1810 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001811 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001812 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001813endfun
1814
1815" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001816" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1817" but only when the options' value and the safe setting differ
1818" Doing this means that netrw will not come up as having changed a
1819" setting last when it really didn't actually change it.
1820"
1821" Called from s:NetrwOptionsSafe
1822" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1823fun! s:NetrwSetSafeSetting(setting,safesetting)
1824" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001825
Bram Moolenaar85850f32019-07-19 22:05:51 +02001826 if a:setting =~ '^&'
1827" call Decho("fyi: a:setting starts with &")
1828 exe "let settingval= ".a:setting
1829" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001830
Bram Moolenaar85850f32019-07-19 22:05:51 +02001831 if settingval != a:safesetting
1832" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1833 if type(a:safesetting) == 0
1834 exe "let ".a:setting."=".a:safesetting
1835 elseif type(a:safesetting) == 1
1836 exe "let ".a:setting."= '".a:safesetting."'"
1837 else
1838 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1839 endif
1840 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001841 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001842
Bram Moolenaar85850f32019-07-19 22:05:51 +02001843" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001844endfun
1845
1846" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001847" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1848" but only if the setting value differs from the associated keepvar.
1849" Doing this means that netrw will not come up as having changed a
1850" setting last when it really didn't actually change it.
1851"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001852" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001853" keepvars are set up by s:NetrwOptionsSave
1854fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001855""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001856
Bram Moolenaar85850f32019-07-19 22:05:51 +02001857 " typically called from s:NetrwOptionsRestore
1858 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1859 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001860 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 if exists(a:keepvar)
1862 exe "let keepvarval= ".a:keepvar
1863 exe "let setting= ".a:setting
1864
1865"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1866"" call Decho("fyi: keepvarval=".keepvarval)
1867"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1868
1869 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001870"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 if type(a:setting) == 0
1872 exe "let ".a:setting."= ".keepvarval
1873 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001874 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001875 else
1876 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1877 endif
1878 endif
1879
1880 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001881 endif
1882
Bram Moolenaar85850f32019-07-19 22:05:51 +02001883"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001884endfun
1885
1886" ---------------------------------------------------------------------
1887" NetrwStatusLine: {{{2
1888fun! NetrwStatusLine()
1889
1890" vvv NetrwStatusLine() debugging vvv
1891" let g:stlmsg=""
1892" if !exists("w:netrw_explore_bufnr")
1893" let g:stlmsg="!X<explore_bufnr>"
1894" elseif w:netrw_explore_bufnr != bufnr("%")
1895" let g:stlmsg="explore_bufnr!=".bufnr("%")
1896" endif
1897" if !exists("w:netrw_explore_line")
1898" let g:stlmsg=" !X<explore_line>"
1899" elseif w:netrw_explore_line != line(".")
1900" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1901" endif
1902" if !exists("w:netrw_explore_list")
1903" let g:stlmsg=" !X<explore_list>"
1904" endif
1905" ^^^ NetrwStatusLine() debugging ^^^
1906
1907 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")
1908 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001909 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001910 let &laststatus = s:netrw_users_ls
1911 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1912 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1913 return ""
1914 else
1915 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1916 endif
1917endfun
1918
Bram Moolenaar85850f32019-07-19 22:05:51 +02001919" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001920" Netrw Transfer Functions: {{{1
1921" ===============================
1922
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001924" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001925" mode: =0 read remote file and insert before current line
1926" =1 read remote file and insert after current line
1927" =2 replace with remote file
1928" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001929fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001930" 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 +00001931
Bram Moolenaar5c736222010-01-06 20:54:52 +01001932 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001933 call s:NetrwOptionsSave("w:")
1934 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001935 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001936 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1937 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1938 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001939" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001940
Bram Moolenaar5c736222010-01-06 20:54:52 +01001941 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001942 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001943 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001944 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001945 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001946 elseif a:mode == 2 " replace with remote file
1947 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001948 elseif a:mode == 3 " skip read of file (leave as temporary)
1949 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001950 else
1951 exe a:mode
1952 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001953 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001954 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001955" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001956
Bram Moolenaar5c736222010-01-06 20:54:52 +01001957 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001958 let tmpfile= s:GetTempfile("")
1959 if tmpfile == ""
1960" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001961 return
1962 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001963
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001964 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001965
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001966 " attempt to repeat with previous host-file-etc
1967 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001968" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001969 let choice = b:netrw_lastfile
1970 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001971
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001972 else
1973 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001974" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001975
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001976 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001977 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001978 echomsg 'NetRead Usage:'
1979 echomsg ':Nread machine:path uses rcp'
1980 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1981 echomsg ':Nread "machine id password path" uses ftp'
1982 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1983 echomsg ':Nread fetch://machine/path uses fetch'
1984 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1985 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001986 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001987 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001988 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1989 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1990 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1991 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001992 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001993 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001994
Bram Moolenaar9964e462007-05-05 17:54:07 +00001995 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001996 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001997" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001998 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001999 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002000 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002001 else
2002 " case "... ... ..."
2003 let choice = strpart(choice,1,strlen(choice)-1)
2004 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002005
Bram Moolenaar9964e462007-05-05 17:54:07 +00002006 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002007 let wholechoice = wholechoice . " " . choice
2008 let ichoice = ichoice + 1
2009 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002010 if !exists("g:netrw_quiet")
2011 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2012 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002013" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002014 return
2015 endif
2016 let choice= a:{ichoice}
2017 endwhile
2018 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2019 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 endif
2021 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002023" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002024 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002025
Bram Moolenaar5c736222010-01-06 20:54:52 +01002026 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002027 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002028 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002029" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002030 return
2031 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002032 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002033
Bram Moolenaar8d043172014-01-23 14:24:41 +01002034 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002035" 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 +02002036 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002037" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002038 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002039" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002040 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002042
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002043 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002044 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002045 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002046 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2047 echo "(netrw) Processing your read request..."
2048 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002051 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002053" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002054 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002055 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002056 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 " ER: the tmpfile is full path: rcp sees C:\... as host C
2058 if s:netrw_has_nt_rcp == 1
2059 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2060 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2061 else
2062 " Any way needed it machine contains a '.'
2063 let uid_machine = g:netrw_machine .'.'. $USERNAME
2064 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2067 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2068 else
2069 let uid_machine = g:netrw_machine
2070 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002072 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 +00002073 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002077 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002080 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002081 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002082 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002083 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002084 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002085" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002086 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002087 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002089 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002090 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002091" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002093 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 +00002094 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002095 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002096 endif
2097 " 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 +00002098 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002099 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002100 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002101 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002102 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002103 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002104 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002105 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002106 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2107 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002108 q!
2109 endif
2110 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002111 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002115 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002116 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2117 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002118" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002119 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002120 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002121 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002122 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002124 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002125" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002126 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002127 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002128" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002129 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002130
Bram Moolenaar97d62492012-11-15 21:28:22 +01002131 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002132 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002133 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002134" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002135 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002136 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002137 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002138" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002139 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002140 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002141" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002142 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002143 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002144
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002145 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002147" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002148 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002149 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002150 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002152 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002153 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002154" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 " perform ftp:
2157 " -i : turns off interactive prompting from ftp
2158 " -n unix : DON'T use <.netrc>, even though it exists
2159 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002160 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002161 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2163 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002164" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002165 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002166 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002167 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002170 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002172
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002174 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002176" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002178 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 else
2180 let useport= ""
2181 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002182 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2183 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002184 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002185 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2186 else
2187 let tmpfile_get = tmpfile
2188 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002189 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 +00002190 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002192
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002194 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002195 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002197 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002198 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002199 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002200 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002201" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002202 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002204
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002205 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2206 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002208 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 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 +00002210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211 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 +00002212 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002213 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002214
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002216 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002217" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002218 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2219 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002220" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2221" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2222 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 +00002223 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002224" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002225 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 endif
2227 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002229 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002232 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002233 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235
Bram Moolenaar5c736222010-01-06 20:54:52 +01002236 if !executable(g:netrw_dav_cmd)
2237 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2238" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2239 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002241 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242 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 +01002243 else
2244 " Construct execution string (four lines) which will be passed through filter
2245 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2246 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002247 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002248 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002250 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002252 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2257 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002258
Bram Moolenaar5c736222010-01-06 20:54:52 +01002259 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002260 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002261 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002263 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002264 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002265 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002266
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002268 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002269 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002271 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 +00002272 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002274
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002276 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002278 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002282 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002283 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002284" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002285 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002287 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 let netrw_option= "http"
2289 else
2290 let netrw_option= "ftp"
2291 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002293
Bram Moolenaar446cb832008-06-24 21:56:24 +00002294 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002295 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 +00002296 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002297 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 +00002298 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002299
Bram Moolenaar446cb832008-06-24 21:56:24 +00002300 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002301 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002302" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002303 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002306 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002307 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2309 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 +00002310 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002312
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002314 " NetRead: (file) NetRead Method #10 {{{3
2315 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2317 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002318 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2319 let b:netrw_lastfile = choice
2320
2321 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002322 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002323 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002324 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002325 endif
2326 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002327
Bram Moolenaar5c736222010-01-06 20:54:52 +01002328 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002329 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 unlet b:netrw_fname
2333 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002334 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 +01002335" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002336 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002337 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002338 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002339
Bram Moolenaar9964e462007-05-05 17:54:07 +00002340" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002341endfun
2342
2343" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002344" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002345fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002346" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002347
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002349 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002350 call s:NetrwOptionsSave("w:")
2351 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002352
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002354 let tmpfile= s:GetTempfile("")
2355 if tmpfile == ""
2356" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002357 return
2358 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002359
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002360 if a:0 == 0
2361 let ichoice = 0
2362 else
2363 let ichoice = 1
2364 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002365
Bram Moolenaar9964e462007-05-05 17:54:07 +00002366 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002367" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002368 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002369 " For binary writes, always write entire file.
2370 " (line numbers don't really make sense for that).
2371 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002372" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002373 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002374 elseif g:netrw_cygwin
2375 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002376 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002377" 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 +01002378 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002379 else
2380 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002381" 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 +01002382 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002383 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002384
Bram Moolenaar9964e462007-05-05 17:54:07 +00002385 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002386 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002387 " on the temporary file's name. Deletion of the temporary file during
2388 " cleanup then causes an error message.
2389 0file!
2390 endif
2391
Bram Moolenaar5c736222010-01-06 20:54:52 +01002392 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002394
Bram Moolenaar9964e462007-05-05 17:54:07 +00002395 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 " attempt to repeat with previous host-file-etc
2397 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002398" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 let choice = b:netrw_lastfile
2400 let ichoice= ichoice + 1
2401 else
2402 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002403
Bram Moolenaar8d043172014-01-23 14:24:41 +01002404 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002406 echomsg 'NetWrite Usage:"'
2407 echomsg ':Nwrite machine:path uses rcp'
2408 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2409 echomsg ':Nwrite "machine id password path" uses ftp'
2410 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2411 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2412 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2413 echomsg ':Nwrite rcp://machine/path uses rcp'
2414 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2415 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2416 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002417 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002419
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002420 elseif match(choice,"^\"") != -1
2421 if match(choice,"\"$") != -1
2422 " case "..."
2423 let choice=strpart(choice,1,strlen(choice)-2)
2424 else
2425 " case "... ... ..."
2426 let choice = strpart(choice,1,strlen(choice)-1)
2427 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002428
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 while match(choice,"\"$") == -1
2430 let wholechoice= wholechoice . " " . choice
2431 let ichoice = ichoice + 1
2432 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002433 if !exists("g:netrw_quiet")
2434 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2435 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002436" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 return
2438 endif
2439 let choice= a:{ichoice}
2440 endwhile
2441 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2442 endif
2443 endif
2444 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002446" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002447
Bram Moolenaar9964e462007-05-05 17:54:07 +00002448 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002449 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002450 if !exists("b:netrw_method") || b:netrw_method < 0
2451" call Dfunc("netrw#NetWrite : unsupported method")
2452 return
2453 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002454
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002455 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002456 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002457 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002458 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2459 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002460" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002461 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002462
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002464 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002465 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002466" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002467 if s:netrw_has_nt_rcp == 1
2468 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2469 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2470 else
2471 let uid_machine = g:netrw_machine .'.'. $USERNAME
2472 endif
2473 else
2474 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2475 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2476 else
2477 let uid_machine = g:netrw_machine
2478 endif
2479 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480 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 +00002481 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002482
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002483 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002484 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002485 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002487 let netrw_fname = b:netrw_fname
2488
2489 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2490 let bhkeep = &l:bh
2491 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002492 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002494
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002495" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002496 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002497 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002498" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002500 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002501" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002502 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002503 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002506 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 +00002507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002508" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2509 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 endif
2511 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2512 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002513 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002514 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002515 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002516 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002518
2519 " remove enew buffer (quietly)
2520 let filtbuf= bufnr("%")
2521 exe curbuf."b!"
2522 let &l:bh = bhkeep
2523 exe filtbuf."bw!"
2524
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002526
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002527 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002528 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002529 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002530 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002531" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002532 let netrw_fname = b:netrw_fname
2533 let bhkeep = &l:bh
2534
2535 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2536 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002537 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002538 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002539 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002540
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002542 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002543" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002544 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002545 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002546" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002547 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002548 if exists("g:netrw_uid") && g:netrw_uid != ""
2549 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002550 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002551" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002552 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002553 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002554 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002555" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002556 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002557 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002558" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002559 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002560 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002561 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002564 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002565" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002567 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002568" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002569 " save choice/id/password for future use
2570 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002571
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 " perform ftp:
2573 " -i : turns off interactive prompting from ftp
2574 " -n unix : DON'T use <.netrc>, even though it exists
2575 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002576 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002577 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002578 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2579 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002580 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002581 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002582 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 let mod=1
2584 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002585
2586 " remove enew buffer (quietly)
2587 let filtbuf= bufnr("%")
2588 exe curbuf."b!"
2589 let &l:bh= bhkeep
2590 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002591
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002593 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002594 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002597 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002598 else
2599 let useport= ""
2600 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601 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 +00002602 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002603
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002604 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002605 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002606 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002608 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2609 if executable(curl)
2610 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611 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 +01002612 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002613 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002614 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002615
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002616 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002617 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002618 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002620
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002621 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002622 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2623 let bhkeep = &l:bh
2624
2625 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2626 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002627 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002628 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002629
Bram Moolenaarff034192013-04-24 18:51:19 +02002630 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002631 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002632 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002633 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002634 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002635 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002636 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002637 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002638 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002639 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002640
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002642 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002643 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644
2645 " remove enew buffer (quietly)
2646 let filtbuf= bufnr("%")
2647 exe curbuf."b!"
2648 let &l:bh = bhkeep
2649 exe filtbuf."bw!"
2650
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002652
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002654 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002655 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002657 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 +00002658 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002659
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002661 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002662 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002664 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2666 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2667 else
2668 let uid_machine = g:netrw_machine
2669 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002670
2671 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2672 let bhkeep = &l:bh
2673 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002674 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676
Bram Moolenaarff034192013-04-24 18:51:19 +02002677 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002678 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002680 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002682 let filtbuf= bufnr("%")
2683 exe curbuf."b!"
2684 let &l:bh = bhkeep
2685 exe filtbuf."bw!"
2686 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002687
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002689 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002690 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002691 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002692 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002695
Bram Moolenaar5c736222010-01-06 20:54:52 +01002696 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002697" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002698 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002699" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002700 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002701 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002702 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002703
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002705 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002706 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" 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 +02002708 elseif !exists("leavemod")
2709 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002710" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002711 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712" 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 +00002713 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002714
Bram Moolenaar9964e462007-05-05 17:54:07 +00002715" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716endfun
2717
2718" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002719" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002720" uses NetRead to get a copy of the file into a temporarily file,
2721" then sources that file,
2722" then removes that file.
2723fun! netrw#NetSource(...)
2724" call Dfunc("netrw#NetSource() a:0=".a:0)
2725 if a:0 > 0 && a:1 == '?'
2726 " give help
2727 echomsg 'NetSource Usage:'
2728 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2729 echomsg ':Nsource fetch://machine/path uses fetch'
2730 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002731 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002732 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2733 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2734 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2735 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2736 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002737 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002738 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002739 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002740 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002742 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002743" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002744 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002745" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002746 if delete(s:netrw_tmpfile)
2747 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2748 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002749 unlet s:netrw_tmpfile
2750 else
2751 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2752 endif
2753 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002754 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002755 endif
2756" call Dret("netrw#NetSource")
2757endfun
2758
Bram Moolenaar8d043172014-01-23 14:24:41 +01002759" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002760" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2761" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002762fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002763
Bram Moolenaar85850f32019-07-19 22:05:51 +02002764 " iscmd==0: netrw#SetTreetop called using gn mapping
2765 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002766 " clear out the current tree
2767 if exists("w:netrw_treetop")
2768 let inittreetop= w:netrw_treetop
2769 unlet w:netrw_treetop
2770 endif
2771 if exists("w:netrw_treedict")
2772 unlet w:netrw_treedict
2773 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002774
Bram Moolenaar85850f32019-07-19 22:05:51 +02002775 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002776 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002777 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002778 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002779 let treedir = a:1
2780 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002782 let treedir = b:netrw_curdir."/".a:1
2783 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002785 " normally the cursor is left in the message window.
2786 " However, here this results in the directory being listed in the message window, which is not wanted.
2787 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002788 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002790 let treedir = "."
2791 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002792 endif
2793 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002794
2795 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002796 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002797
2798 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002799 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002800 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002801 else
Tom Benham64a536d2024-11-07 21:15:03 +01002802 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002803 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002804
Bram Moolenaar8d043172014-01-23 14:24:41 +01002805endfun
2806
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002808" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809" readcmd == %r : replace buffer with newly read file
2810" == 0r : read file at top of buffer
2811" == r : read file after current line
2812" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002813fun! s:NetrwGetFile(readcmd, tfile, method)
2814" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815
2816 " readcmd=='t': simply do nothing
2817 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002819" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002820 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002821 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002822
Bram Moolenaar9964e462007-05-05 17:54:07 +00002823 " get name of remote filename (ie. url and all)
2824 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002826
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827 if exists("*NetReadFixup")
2828 " for the use of NetReadFixup (not otherwise used internally)
2829 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002830 endif
2831
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832 if a:readcmd[0] == '%'
2833 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002834" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002835
2836 " rename the current buffer to the temp file (ie. tfile)
2837 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002838 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002839 else
2840 let tfile= a:tfile
2841 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002842 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843
2844 " edit temporary file (ie. read the temporary file in)
2845 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 call zip#Browse(tfile)
2848 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002851 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002854 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002857 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002859 call tar#Browse(tfile)
2860 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002862 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002864" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002865 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002866 endif
2867
2868 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002869 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002870
Bram Moolenaar71badf92023-04-22 22:40:14 +01002871 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002872 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002873 " Note that isk must not include a "/" for scripts.vim
2874 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002875" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2876" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002877" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002878" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2879 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002880 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002881 filetype detect
2882" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002883 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002884" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002885 let line1 = 1
2886 let line2 = line("$")
2887
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 elseif !&ma
2889 " 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 +01002890 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002891" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002892 return
2893
Bram Moolenaar9964e462007-05-05 17:54:07 +00002894 elseif s:FileReadable(a:tfile)
2895 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002897 let curline = line(".")
2898 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002900 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002901 let line1= curline + 1
2902 let line2= line("$") - lastline + 1
2903
2904 else
2905 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2907" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002908 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002909" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002910 return
2911 endif
2912
2913 " User-provided (ie. optional) fix-it-up command
2914 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002916 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002917" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002919 endif
2920
Bram Moolenaaradc21822011-04-01 18:03:16 +02002921 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002922 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002923 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924 endif
2925
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002926" 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 +00002927
2928 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002929" redraw!
2930
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002931" 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 +00002932" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002933endfun
2934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002937" Input:
2938" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2939" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002940" b:netrw_method= 1: rcp
2941" 2: ftp + <.netrc>
2942" 3: ftp + machine, id, password, and [path]filename
2943" 4: scp
2944" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002945" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" 7: rsync
2947" 8: fetch
2948" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002949" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002950" g:netrw_machine= hostname
2951" b:netrw_fname = filename
2952" g:netrw_port = optional port number (for ftp)
2953" g:netrw_choice = copy of input url (choice)
2954fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002955" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002956
Bram Moolenaar251e1912011-06-19 05:09:16 +02002957 " sanity check: choice should have at least three slashes in it
2958 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2959 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2960 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002961" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002962 return
2963 endif
2964
Bram Moolenaar5c736222010-01-06 20:54:52 +01002965 " record current g:netrw_machine, if any
2966 " curmachine used if protocol == ftp and no .netrc
2967 if exists("g:netrw_machine")
2968 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002970 else
2971 let curmachine= "N O T A HOST"
2972 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002973 if exists("g:netrw_port")
2974 let netrw_port= g:netrw_port
2975 endif
2976
2977 " insure that netrw_ftp_cmd starts off every method determination
2978 " with the current g:netrw_ftp_cmd
2979 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002980
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002981 " initialization
2982 let b:netrw_method = 0
2983 let g:netrw_machine = ""
2984 let b:netrw_fname = ""
2985 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002986 let g:netrw_choice = a:choice
2987
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002988 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002989 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002990 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2991 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002992 " rcpurm : rcp://[user@]host/filename Use rcp
2993 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002994 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002995 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002996 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002997 " rsyncurm : rsync://host[:port]/path Use rsync
2998 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2999 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003000 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003001 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3002 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003003 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3004 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003005 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003006 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003007 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003008 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003009 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003010 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003011 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003012 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003013
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003014" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003015 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003016 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003017 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003019 let b:netrw_method = 1
3020 let userid = substitute(a:choice,rcpurm,'\1',"")
3021 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3022 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003023 if userid != ""
3024 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003026
Bram Moolenaaradc21822011-04-01 18:03:16 +02003027 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003028 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003029" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003030 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003031 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3032 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3033 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003034
Bram Moolenaar15146672011-10-20 22:22:38 +02003035 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003036 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003037" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003038 let b:netrw_method = 5
3039 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3040 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003041 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003042
Bram Moolenaaradc21822011-04-01 18:03:16 +02003043 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003044 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003045" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003046 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003047 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003048 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3049 else
3050 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3051 endif
3052 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003053
Bram Moolenaaradc21822011-04-01 18:03:16 +02003054 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003055 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003056" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003057 let b:netrw_method = 7
3058 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3059 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003060
Bram Moolenaaradc21822011-04-01 18:03:16 +02003061 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003062 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003064 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003065 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3066 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3067 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003068" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003069 if userid != ""
3070 let g:netrw_uid= userid
3071 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003072
Bram Moolenaaradc21822011-04-01 18:03:16 +02003073 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003074 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003075 call NetUserPass("ftp:".g:netrw_machine)
3076 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003077 " if there's a change in hostname, require password re-entry
3078 unlet s:netrw_passwd
3079 endif
3080 if exists("netrw_port")
3081 unlet netrw_port
3082 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003083 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003084
Bram Moolenaar446cb832008-06-24 21:56:24 +00003085 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003086 let b:netrw_method = 3
3087 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003088 let host= substitute(g:netrw_machine,'\..*$','','')
3089 if exists("s:netrw_hup[host]")
3090 call NetUserPass("ftp:".host)
3091
Nir Lichtman1e34b952024-05-08 19:19:34 +02003092 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003093" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3094" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003095 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003096 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003098 endif
3099 let b:netrw_method= 2
3100 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003101" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003102 let b:netrw_method= 2
3103 else
3104 if !exists("g:netrw_uid") || g:netrw_uid == ""
3105 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003106 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003108 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 endif
3110 let b:netrw_method= 3
3111 endif
3112 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003113
Bram Moolenaaradc21822011-04-01 18:03:16 +02003114 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003116" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 let b:netrw_method = 8
3118 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3119 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3120 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3121 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003122
Bram Moolenaaradc21822011-04-01 18:03:16 +02003123 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003125" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3128 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003129 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003131 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003132
Bram Moolenaaradc21822011-04-01 18:03:16 +02003133 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003135" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003136 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let b:netrw_method = 3
3138 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3139 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003140
Bram Moolenaar9964e462007-05-05 17:54:07 +00003141 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 let b:netrw_method = 2
3143 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3144 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3145 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003146
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003149" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003150 let b:netrw_method = 9
3151 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3152 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaaradc21822011-04-01 18:03:16 +02003154 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003157 let b:netrw_method = 1
3158 let userid = substitute(a:choice,rcphf,'\2',"")
3159 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3160 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3162" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3163" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3164" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 if userid != ""
3166 let g:netrw_uid= userid
3167 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003168
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003169 " Method#10: file://user@hostname/...path-to-file {{{3
3170 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003172 let b:netrw_method = 10
3173 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003174" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003175
Bram Moolenaaradc21822011-04-01 18:03:16 +02003176 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003178 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003179 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003180 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003184
Bram Moolenaar81695252004-12-29 20:58:21 +00003185 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003186 " remove any leading [:#] from port number
3187 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3188 elseif exists("netrw_port")
3189 " retain port number as implicit for subsequent ftp operations
3190 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003191 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003192
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003193" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3194" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3195" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3196" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003197" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003198" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003199" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003200" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003201" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003202" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003203" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003204" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206
Bram Moolenaar9964e462007-05-05 17:54:07 +00003207" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003208" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209" Usage: :call NetUserPass() -- will prompt for userid and password
3210" :call NetUserPass("uid") -- will prompt for password
3211" :call NetUserPass("uid","password") -- sets global userid and password
3212" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3213" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214fun! NetUserPass(...)
3215
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003216" call Dfunc("NetUserPass() a:0=".a:0)
3217
3218 if !exists('s:netrw_hup')
3219 let s:netrw_hup= {}
3220 endif
3221
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003223 " case: no input arguments
3224
3225 " change host and username if not previously entered; get new password
3226 if !exists("g:netrw_machine")
3227 let g:netrw_machine= input('Enter hostname: ')
3228 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003230 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 let g:netrw_uid= input('Enter username: ')
3232 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003233 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003234 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003235
3236 " set up hup database
3237 let host = substitute(g:netrw_machine,'\..*$','','')
3238 if !exists('s:netrw_hup[host]')
3239 let s:netrw_hup[host]= {}
3240 endif
3241 let s:netrw_hup[host].uid = g:netrw_uid
3242 let s:netrw_hup[host].passwd = s:netrw_passwd
3243
3244 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003245 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003246
3247 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003248 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003249 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003250" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003251 let host = substitute(a:1,'^ftp:','','')
3252 let host = substitute(host,'\..*','','')
3253 if exists("s:netrw_hup[host]")
3254 let g:netrw_uid = s:netrw_hup[host].uid
3255 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003256" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3257" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003258 else
3259 let g:netrw_uid = input("Enter UserId: ")
3260 let s:netrw_passwd = inputsecret("Enter Password: ")
3261 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003262
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003263 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003264 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003265" 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 +02003266 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003267 if g:netrw_machine =~ '[0-9.]\+'
3268 let host= g:netrw_machine
3269 else
3270 let host= substitute(g:netrw_machine,'\..*$','','')
3271 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003272 else
3273 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003274 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003275 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003276" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003277 if exists("g:netrw_passwd")
3278 " ask for password if one not previously entered
3279 let s:netrw_passwd= g:netrw_passwd
3280 else
3281 let s:netrw_passwd = inputsecret("Enter Password: ")
3282 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003283 endif
3284
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003286 if exists("host")
3287 if !exists('s:netrw_hup[host]')
3288 let s:netrw_hup[host]= {}
3289 endif
3290 let s:netrw_hup[host].uid = g:netrw_uid
3291 let s:netrw_hup[host].passwd = s:netrw_passwd
3292 endif
3293
3294 elseif a:0 == 2
3295 let g:netrw_uid = a:1
3296 let s:netrw_passwd = a:2
3297
3298 elseif a:0 == 3
3299 " enter hostname, user-id, and password into the hup dictionary
3300 let host = substitute(a:1,'^\a\+:','','')
3301 let host = substitute(host,'\..*$','','')
3302 if !exists('s:netrw_hup[host]')
3303 let s:netrw_hup[host]= {}
3304 endif
3305 let s:netrw_hup[host].uid = a:2
3306 let s:netrw_hup[host].passwd = a:3
3307 let g:netrw_uid = s:netrw_hup[host].uid
3308 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003309" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3310" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003312
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003313" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315
Bram Moolenaar85850f32019-07-19 22:05:51 +02003316" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003317" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003318" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003320" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003321" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3322fun! s:ExplorePatHls(pattern)
3323" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3324 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003326 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003328 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3329" call Dret("s:ExplorePatHls repat<".repat.">")
3330 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003331endfun
3332
3333" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003334" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003335" 0: (user: <mb>) bookmark current directory
3336" 1: (user: <gb>) change to the bookmarked directory
3337" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003338" 3: (browsing) records current directory history
3339" 4: (user: <u>) go up (previous) directory, using history
3340" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003341" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003342fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003343" 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 +02003344 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3345" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3346 return
3347 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003348
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003349 let ykeep = @@
3350 let curbufnr = bufnr("%")
3351
Bram Moolenaar9964e462007-05-05 17:54:07 +00003352 if a:chg == 0
3353 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003354" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003355 if exists("s:netrwmarkfilelist_{curbufnr}")
3356 call s:NetrwBookmark(0)
3357 echo "bookmarked marked files"
3358 else
3359 call s:MakeBookmark(a:curdir)
3360 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003361 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003362
KSR-Yasudaf4498252023-10-06 03:34:17 +09003363 try
3364 call s:NetrwBookHistSave()
3365 catch
3366 endtry
3367
Bram Moolenaar9964e462007-05-05 17:54:07 +00003368 elseif a:chg == 1
3369 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003370" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003371 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003372" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003373 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003374 else
3375 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3376 endif
3377
3378 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003379" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003380 let didwork= 0
3381 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003382" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003383 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003384" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003385 let cnt= 1
3386 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003387" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003388 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003389 let didwork = 1
3390 let cnt = cnt + 1
3391 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003392 endif
3393
3394 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003395 " Note: history is saved only when PerformListing is done;
3396 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3397 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003398 let first = 1
3399 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003400 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003401 while ( first || cnt != g:netrw_dirhistcnt )
3402" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003403 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003404" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003405 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003406 let didwork= 1
3407 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003408 let histcnt = histcnt + 1
3409 let first = 0
3410 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003411 if cnt < 0
3412 let cnt= cnt + g:netrw_dirhistmax
3413 endif
3414 endwhile
3415 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003416 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003417 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003418 if didwork
3419 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3420 endif
3421
3422 elseif a:chg == 3
3423 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003424" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003425 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 +02003426 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003427 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3428 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003429 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003430" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003431 endif
3432
3433 elseif a:chg == 4
3434 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003435" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003436 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003437 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3438 if g:netrw_dirhistcnt < 0
3439 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003440 endif
3441 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003442 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003444 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3445" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003446 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003447 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("setl ma noro",'~'.expand("<slnum>"))
3449 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003450 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003451" call Decho("setl nomod",'~'.expand("<slnum>"))
3452" 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 +00003453 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003454" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3455 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003456 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003457 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003458 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003459 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003460 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003461 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003462 echo "Sorry, no predecessor directory exists yet"
3463 endif
3464
3465 elseif a:chg == 5
3466 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003467" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003468 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003469 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3470 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3471" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003472 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003474 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003475 sil! NetrwKeepj %d _
3476" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3477" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003478 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003479" 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 +02003480 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003481" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3482 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003483 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003484 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3485 if g:netrw_dirhistcnt < 0
3486 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003487 endif
3488 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003490 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003491 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003492 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003493 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003494
3495 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003496" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003497 if exists("s:netrwmarkfilelist_{curbufnr}")
3498 call s:NetrwBookmark(1)
3499 echo "removed marked files from bookmarks"
3500 else
3501 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502 let iremove = v:count
3503 let dremove = g:netrw_bookmarklist[iremove - 1]
3504" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003505 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3507 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3508 echo "removed ".dremove." from g:netrw_bookmarklist"
3509" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003510 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003511" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003512
3513 try
3514 call s:NetrwBookHistSave()
3515 catch
3516 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003518 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003519 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003520 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003521" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003522endfun
3523
3524" ---------------------------------------------------------------------
3525" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003526" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003527" Sister function: s:NetrwBookHistSave()
3528fun! s:NetrwBookHistRead()
3529" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003530 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003531" 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 +02003532 return
3533 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003534 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535
3536 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003537 if !exists("s:netrw_initbookhist")
3538 let home = s:NetrwHome()
3539 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003540 if filereadable(s:NetrwFile(savefile))
3541" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003542 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003543 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003544
3545 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003546 if g:netrw_dirhistmax > 0
3547 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003548 if filereadable(s:NetrwFile(savefile))
3549" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003550 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 endif
3552 let s:netrw_initbookhist= 1
3553 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003554 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003555 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556
Bram Moolenaar97d62492012-11-15 21:28:22 +01003557 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3559" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003560" call Dret("s:NetrwBookHistRead")
3561endfun
3562
3563" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003564" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003565" Sister function: s:NetrwBookHistRead()
3566" I used to do this via viminfo but that appears to
3567" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003568" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3569" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003571fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003573 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003574" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003575 return
3576 endif
3577
Bram Moolenaar5c736222010-01-06 20:54:52 +01003578 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003579" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003580 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003581
3582 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003583 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003585 if g:netrw_use_noswf
3586 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3587 else
3588 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3589 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003590 setl nocin noai noci magic nospell nohid wig= noaw
3591 setl ma noro write
3592 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003593 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003594
Bram Moolenaar85850f32019-07-19 22:05:51 +02003595 " rename enew'd file: .netrwhist -- no attempt to merge
3596 " record dirhistmax and current dirhistcnt
3597 " save history
3598" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003599 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003600 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3602 if g:netrw_dirhistmax > 0
3603 let lastline = line("$")
3604 let cnt = g:netrw_dirhistcnt
3605 let first = 1
3606 while ( first || cnt != g:netrw_dirhistcnt )
3607 let lastline= lastline + 1
3608 if exists("g:netrw_dirhist_{cnt}")
3609 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3610" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3611 endif
3612 let first = 0
3613 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3614 if cnt < 0
3615 let cnt= cnt + g:netrw_dirhistmax
3616 endif
3617 endwhile
3618 exe "sil! w! ".savefile
3619" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3620 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003621
Bram Moolenaar85850f32019-07-19 22:05:51 +02003622 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003623 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003624 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003625" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003626 " merge and write .netrwbook
3627 let savefile= s:NetrwHome()."/.netrwbook"
3628
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003629 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003632 for bdm in booklist
3633 if index(g:netrw_bookmarklist,bdm) == -1
3634 call add(g:netrw_bookmarklist,bdm)
3635 endif
3636 endfor
3637 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003638 endif
3639
3640 " construct and save .netrwbook
3641 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003642 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003644 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645
3646 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647 let bgone= bufnr("%")
3648 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003649 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003650
3651" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003652endfun
3653
3654" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003655" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3656" list of the contents of a local or remote directory. It is assumed that the
3657" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3658" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003659" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003660fun! s:NetrwBrowse(islocal,dirname)
3661 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003662
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003663 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3664 " This is useful when one edits a local file, then :e ., then :Rex
3665 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3666 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003667 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003669 " s:NetrwBrowse : initialize history {{{3
3670 if !exists("s:netrw_initbookhist")
3671 NetrwKeepj call s:NetrwBookHistRead()
3672 endif
3673
3674 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003675 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676 let dirname= simplify(a:dirname)
3677 else
3678 let dirname= a:dirname
3679 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003680
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681 " repoint t:netrw_lexbufnr if appropriate
3682 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003683 let repointlexbufnr= 1
3684 endif
3685
3686 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003687 if exists("s:netrw_skipbrowse")
3688 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003689 return
3690 endif
3691 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003692 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003693 return
3694 endif
3695 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003697 return
3698 endif
3699
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003700 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003701 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003702
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003703 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3705 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003706 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3707 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003708 endif
3709
3710 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003711 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713 return
3714 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003715
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003717 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003718 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003719 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003720 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003721 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003722
3723 " remove any filetype indicator from end of dirname, except for the
3724 " "this is a directory" indicator (/).
3725 " There shouldn't be one of those here, anyway.
3726 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003727 call s:RemotePathAnalysis(dirname)
3728
3729 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3730 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003731 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003732 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003733 let b:netrw_curdir = dirname
3734 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003735 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003736 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3737 sil call netrw#NetRead(2,url)
3738 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003739 if s:path =~ '.bz2'
3740 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3741 elseif s:path =~ '.gz'
3742 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3743 elseif s:path =~ '.gz'
3744 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3745 else
3746 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3747 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003748 endif
3749
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003750 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003751 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003752 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003753 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003754 return
3755 endif
3756
Bram Moolenaaradc21822011-04-01 18:03:16 +02003757 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003758 call s:UseBufWinVars()
3759
3760 " set up some variables {{{3
3761 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763 let s:last_sort_by = g:netrw_sort_by
3764
3765 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003766 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767
Bram Moolenaar97d62492012-11-15 21:28:22 +01003768 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003769 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003770
3771 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3772 " previous buffer
3773 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003774 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003775 if exists("s:rexposn_".prevbufnr)
3776 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3777 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003778
Bram Moolenaar446cb832008-06-24 21:56:24 +00003779 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003780 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3781 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003782 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3783 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003784 2match none
3785 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003786 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003787 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003788 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003789 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003790 return
3791 endif
3792
3793 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003794 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003795 if b:netrw_curdir =~ '[/\\]$'
3796 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3797 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003798 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003799 let b:netrw_curdir= b:netrw_curdir."/"
3800 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801 if b:netrw_curdir == ''
3802 if has("amiga")
3803 " On the Amiga, the empty string connotes the current directory
3804 let b:netrw_curdir= getcwd()
3805 else
3806 " under unix, when the root directory is encountered, the result
3807 " from the preceding substitute is an empty string.
3808 let b:netrw_curdir= '/'
3809 endif
3810 endif
3811 if !a:islocal && b:netrw_curdir !~ '/$'
3812 let b:netrw_curdir= b:netrw_curdir.'/'
3813 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814
3815 " ------------
3816 " (local only) {{{3
3817 " ------------
3818 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819 " Set up ShellCmdPost handling. Append current buffer to browselist
3820 call s:LocalFastBrowser()
3821
3822 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3823 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003824 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003825 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003826 return
3827 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003828 endif
3829 endif
3830
3831 " --------------------------------
3832 " remote handling: {{{3
3833 " --------------------------------
3834 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835
Bram Moolenaar97d62492012-11-15 21:28:22 +01003836 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003837 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003838 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003839 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3840 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3841 if dirname !~ '/$'
3842 let dirname= dirname.'/'
3843 endif
3844 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003846 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003847 endif
3848
3849 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3850 if dirname !~ dirpat
3851 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003852 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003854 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003855 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856 return
3857 endif
3858 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003859 endif " (additional remote handling)
3860
Bram Moolenaar85850f32019-07-19 22:05:51 +02003861 " -------------------------------
3862 " Perform Directory Listing: {{{3
3863 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 NetrwKeepj call s:NetrwMaps(a:islocal)
3865 NetrwKeepj call s:NetrwCommands(a:islocal)
3866 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003868 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003869 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003870
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871 " If there is a rexposn: restore position with rexposn
3872 " Otherwise : set rexposn
3873 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003874 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3875 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3876 NetrwKeepj exe w:netrw_bannercnt
3877 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003878 else
3879 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3880 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003881 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003882 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003883 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003884 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003885
Bram Moolenaar85850f32019-07-19 22:05:51 +02003886 " repoint t:netrw_lexbufnr if appropriate
3887 if exists("repointlexbufnr")
3888 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003889 endif
3890
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003891 " restore position
3892 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003893 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 endif
3895
Bram Moolenaara6878372014-03-22 21:02:50 +01003896 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003897 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3898 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003899 return
3900endfun
3901
3902" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003903" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3904" may not apply correctly; ie. netrw's idea of the current directory may
3905" differ from vim's. This function insures that netrw's idea of the current
3906" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003907" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003908fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003909" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3910" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3911" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3912" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3913" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003914
3915 " clean up any leading treedepthstring
3916 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3917 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003918" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003919 else
3920 let fname= a:fname
3921 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003922
3923 if g:netrw_keepdir
3924 " vim's idea of the current directory possibly may differ from netrw's
3925 if !exists("b:netrw_curdir")
3926 let b:netrw_curdir= getcwd()
3927 endif
3928
Nir Lichtman1e34b952024-05-08 19:19:34 +02003929 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003930 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003931 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003932 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003933" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003934 else
3935 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003936 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003937" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938 endif
3939
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003940 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003942 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003943" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944 else
3945 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003946 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003947" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003948 endif
3949 else
3950 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003951 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003952" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3953" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3954" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003955 endif
3956
Bram Moolenaar85850f32019-07-19 22:05:51 +02003957" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003958 return ret
3959endfun
3960
3961" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003962" s:NetrwFileInfo: supports qf (query for file information) {{{2
3963fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003964" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003965 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003967 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003968 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003969 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003970 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003971 let lsopt= "-lsadh --si"
3972 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003973" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003975
3976 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003977 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003979
Bram Moolenaara6878372014-03-22 21:02:50 +01003980 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003981 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003983
3984 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003985 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003987
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003989" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003990 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992 endif
3993 else
3994 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3996 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003997 let fname= substitute(a:fname,".$","","")
3998 else
3999 let fname= a:fname
4000 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001 let t = getftime(s:NetrwFile(fname))
4002 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004003 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004004 let sz= s:NetrwHumanReadable(sz)
4005 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4007" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004008 endif
4009 else
4010 echo "sorry, \"qf\" not supported yet for remote files"
4011 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004012 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004013" call Dret("s:NetrwFileInfo")
4014endfun
4015
4016" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004017" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4018fun! s:NetrwFullPath(filename)
4019" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4020 let filename= a:filename
4021 if filename !~ '^/'
4022 let filename= resolve(getcwd().'/'.filename)
4023 endif
4024 if filename != "/" && filename =~ '/$'
4025 let filename= substitute(filename,'/$','','')
4026 endif
4027" " call Dret("s:NetrwFullPath <".filename.">")
4028 return filename
4029endfun
4030
4031" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004033" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004034" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004035" 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 +00004036fun! s:NetrwGetBuffer(islocal,dirname)
4037" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004038" 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 +02004039" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4040" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004041 let dirname= a:dirname
4042
4043 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004044" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004045 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004046" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004047 let s:netrwbuf= {}
4048 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004049" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4050" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4051
4052 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4053 let bufnum = -1
4054
4055 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4056 if has_key(s:netrwbuf,"NetrwTreeListing")
4057 let bufnum= s:netrwbuf["NetrwTreeListing"]
4058 else
4059 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4060 endif
4061" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4062 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004063 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004064 let bufnum= -1
4065 endif
4066 elseif bufnr("NetrwTreeListing") != -1
4067 let bufnum= bufnr("NetrwTreeListing")
4068" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4069 else
4070" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4071 let bufnum= -1
4072 endif
4073
4074 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004075 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004077 if !bufexists(bufnum)
4078 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4079 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004080 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081
Bram Moolenaar446cb832008-06-24 21:56:24 +00004082 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004083" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004084 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004085 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004086" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4087
Bram Moolenaar71badf92023-04-22 22:40:14 +01004088 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004089 " IF the buffer already has the desired name
4090 " AND it is empty
4091 let curbuf = bufname("%")
4092 if curbuf == '.'
4093 let curbuf = getcwd()
4094 endif
4095" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004096" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004097" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4098" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4099" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4100" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4101 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004102" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4103 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004104 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004105" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004106 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004107 " 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 +00004108
4109 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004110 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111" 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 +00004112 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004114 " name the buffer
4115 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4116 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118 let w:netrw_treebufnr = bufnr("%")
4119 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004120 if g:netrw_use_noswf
4121 setl nobl bt=nofile noswf
4122 else
4123 setl nobl bt=nofile
4124 endif
4125 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4126 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4127 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4128 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004130 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004131 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004132 " enter the new buffer into the s:netrwbuf dictionary
4133 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4134" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4135" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004138
4139 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004140" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004141 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004142 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004143 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004144
4145 if &ft == "netrw"
4146" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4147 exe "sil! NetrwKeepj noswapfile b ".bufnum
4148" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004150" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4151 call s:NetrwEditBuf(bufnum)
4152" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004154" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004155 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004156 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004158
4159 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004160 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004161
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162 if line("$") <= 1 && getline(1) == ""
4163 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004164 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" 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>"))
4166" 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 +01004167" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4168 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004169
Bram Moolenaar97d62492012-11-15 21:28:22 +01004170 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004172 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173 sil NetrwKeepj %d _
4174" 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>"))
4175" 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 +01004176" 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 +00004177 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004178
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4181" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004182 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004183 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004184 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004185" 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>"))
4186" 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 +01004187" 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 +00004188 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004189
Bram Moolenaar446cb832008-06-24 21:56:24 +00004190 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004191" 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>"))
4192" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4193" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004194 return 1
4195 endif
4196 endif
4197
4198 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4199 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4200 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4201 " med 1 D H
4202 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004203" 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 +00004204 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004205 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004206 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207
4208 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004209" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4210" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4211 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004213" 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>"))
4214" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4215" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004216 return 0
4217endfun
4218
4219" ---------------------------------------------------------------------
4220" s:NetrwGetcwd: get the current directory. {{{2
4221" Change backslashes to forward slashes, if any.
4222" If doesc is true, escape certain troublesome characters
4223fun! s:NetrwGetcwd(doesc)
4224" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4225 let curdir= substitute(getcwd(),'\\','/','ge')
4226 if curdir !~ '[\/]$'
4227 let curdir= curdir.'/'
4228 endif
4229 if a:doesc
4230 let curdir= fnameescape(curdir)
4231 endif
4232" call Dret("NetrwGetcwd <".curdir.">")
4233 return curdir
4234endfun
4235
4236" ---------------------------------------------------------------------
4237" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4238fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004239" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4240" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4241 let keepsol= &l:sol
4242 setl nosol
4243
Bram Moolenaar446cb832008-06-24 21:56:24 +00004244 call s:UseBufWinVars()
4245
4246 " insure that w:netrw_liststyle is set up
4247 if !exists("w:netrw_liststyle")
4248 if exists("g:netrw_liststyle")
4249 let w:netrw_liststyle= g:netrw_liststyle
4250 else
4251 let w:netrw_liststyle= s:THINLIST
4252 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004253" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 endif
4255
4256 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4257 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004258" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004259 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 let dirname= "./"
4261 let curline= getline('.')
4262
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004263 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004264 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 let s:netrw_skipbrowse= 1
4266 echo 'Pressing "s" also works'
4267
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004268 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004269 let s:netrw_skipbrowse= 1
4270 echo 'Press "S" to edit sorting sequence'
4271
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004272 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004273 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004274 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004275
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004276 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004277 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004278 let s:netrw_skipbrowse= 1
4279 echo 'Pressing "a" also works'
4280
4281 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004282 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004283 endif
4284
4285 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004287 NetrwKeepj norm! 0
4288 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004289
4290 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004292 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004293 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4294
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004295 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004297 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004298 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004299
4300 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004301" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004302 let dirname= getline('.')
4303
4304 if !exists("b:netrw_cpf")
4305 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004306 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 +01004307 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004308" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309 endif
4310
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004313" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4314" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004316 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 else
4318 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004319 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320 endif
Enno3146d632024-07-04 19:44:42 +02004321
4322 let dict={}
4323 " save the unnamed register and register 0-9 and a
4324 let dict.a=[getreg('a'), getregtype('a')]
4325 for i in range(0, 9)
4326 let dict[i] = [getreg(i), getregtype(i)]
4327 endfor
4328 let dict.unnamed = [getreg(''), getregtype('')]
4329
Bram Moolenaarc236c162008-07-13 17:41:49 +00004330 let eofname= filestart + b:netrw_cpf + 1
4331 if eofname <= col("$")
4332 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004333 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004334 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004336 endif
Enno3146d632024-07-04 19:44:42 +02004337
Bram Moolenaar446cb832008-06-24 21:56:24 +00004338 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004339 call s:RestoreRegister(dict)
4340
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004343" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004344 endif
4345
4346 " symlinks are indicated by a trailing "@". Remove it before further processing.
4347 let dirname= substitute(dirname,"@$","","")
4348
4349 " executables are indicated by a trailing "*". Remove it before further processing.
4350 let dirname= substitute(dirname,"\*$","","")
4351
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352 let &l:sol= keepsol
4353
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354" call Dret("s:NetrwGetWord <".dirname.">")
4355 return dirname
4356endfun
4357
4358" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004359" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4360" g:netrw_bufsettings will be used after the listing is produced.
4361" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004362fun! s:NetrwListSettings(islocal)
4363" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" 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 +00004365 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004366" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4367 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4368 setl bt=nofile nobl ma nonu nowrap noro nornu
4369 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004371 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004373" call Dredir("ls!","s:NetrwListSettings")
4374" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004375 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004376 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004378 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004380 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004383" call Dret("s:NetrwListSettings")
4384endfun
4385
4386" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004387" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388" islocal=0: remote browsing
4389" =1: local browsing
4390fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004391 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392 let fname = s:NetrwGetWord()
4393 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004394 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004395 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004396
Bram Moolenaar85850f32019-07-19 22:05:51 +02004397 " repoint t:netrw_lexbufnr if appropriate
4398 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004399 let repointlexbufnr= 1
4400 endif
4401
Bram Moolenaar446cb832008-06-24 21:56:24 +00004402 if w:netrw_liststyle == s:THINLIST
4403 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004404 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4405
4406 elseif w:netrw_liststyle == s:LONGLIST
4407 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4409
4410 elseif w:netrw_liststyle == s:WIDELIST
4411 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4413
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004414 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4416
4417 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004418 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004419 let g:netrw_liststyle = s:THINLIST
4420 let w:netrw_liststyle = g:netrw_liststyle
4421 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4422 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004423 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424
4425 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004426 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004427 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004428 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429
4430 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004431 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004432 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433
Bram Moolenaar85850f32019-07-19 22:05:51 +02004434 " repoint t:netrw_lexbufnr if appropriate
4435 if exists("repointlexbufnr")
4436 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004437 endif
4438
Bram Moolenaar13600302014-05-22 18:26:40 +02004439 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004440" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4441 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004442 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444endfun
4445
4446" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004447" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4448fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004449 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004450 " toggle the banner (enable/suppress)
4451 let g:netrw_banner= !g:netrw_banner
4452
4453 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004454 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004455 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004456
4457 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004458 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4459 let fname= s:NetrwGetWord()
4460 sil NetrwKeepj $
4461 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4462" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4463 if result <= 0 && exists("w:netrw_bannercnt")
4464 exe "NetrwKeepj ".w:netrw_bannercnt
4465 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004466 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004467 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004468" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4469endfun
4470
4471" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004472" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4473"
4474" No bang: enters files/directories into Netrw's bookmark system
4475" No argument and in netrw buffer:
4476" if there are marked files: bookmark marked files
4477" otherwise : bookmark file/directory under cursor
4478" No argument and not in netrw buffer: bookmarks current open file
4479" Has arguments: globs them individually and bookmarks them
4480"
4481" With bang: deletes files/directories from Netrw's bookmark system
4482fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004483 if a:0 == 0
4484 if &ft == "netrw"
4485 let curbufnr = bufnr("%")
4486
4487 if exists("s:netrwmarkfilelist_{curbufnr}")
4488 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004489 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004491 for fname in s:netrwmarkfilelist_{curbufnr}
4492 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4493 endfor
4494 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4495 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004496 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004497 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 else
4499 let fname= s:NetrwGetWord()
4500 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4501 endif
4502
4503 else
4504 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004505 let fname= expand("%")
4506 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4507 endif
4508
4509 else
4510 " bookmark specified files
4511 " attempts to infer if working remote or local
4512 " by deciding if the current file begins with an url
4513 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004514 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004515 let i = 1
4516 while i <= a:0
4517 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004518 if v:version > 704 || (v:version == 704 && has("patch656"))
4519 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004520 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004521 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004523 else
4524 let mbfiles= [a:{i}]
4525 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004526 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004527 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4528 endfor
4529 let i= i + 1
4530 endwhile
4531 endif
4532
4533 " update the menu
4534 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004535endfun
4536
4537" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4539" .2.[cnt] for bookmarks, and
4540" .3.[cnt] for history
4541" (see s:NetrwMenu())
4542fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004543 if !exists("s:netrw_menucnt")
4544 return
4545 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004546" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547
4548 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004549 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004550 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004551" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004552 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4553 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004554 endif
4555 if !exists("s:netrw_initbookhist")
4556 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004557 endif
4558
4559 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004560 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004561 let cnt= 1
4562 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004563" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004564 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004565
4566 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004567 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004568
4569 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004570 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 +01004571 let cnt= cnt + 1
4572 endfor
4573
4574 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004575
4576 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004577 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004578 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004579 let first = 1
4580 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004581 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004582 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004583 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004584 if exists("g:netrw_dirhist_{cnt}")
4585 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004586" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004587 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4588 endif
4589 let first = 0
4590 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4591 if cnt < 0
4592 let cnt= cnt + g:netrw_dirhistmax
4593 endif
4594 endwhile
4595 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004596
Bram Moolenaar9964e462007-05-05 17:54:07 +00004597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004599endfun
4600
4601" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4603" directory and a new directory name. Also, if the
4604" "new directory name" is actually a file,
4605" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004606" cursor=0: newdir is relative to b:netrw_curdir
4607" =1: newdir is relative to the path to the word under the cursor in
4608" tree view
4609fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004610 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004611 if !exists("b:netrw_curdir")
4612 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4613 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004614 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004615 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004616 endif
4617
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004618 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004619 call s:SavePosn(s:netrw_posn)
4620 NetrwKeepj call s:NetrwOptionsSave("s:")
4621 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004622
4623 let newdir = a:newdir
4624 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4625 " dirname is the path to the word under the cursor
4626 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004627 " newdir resolves to a directory and points to a directory in dirname
4628 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4629 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4630 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4631 let newdir = fnamemodify(resolve(newdir), ':t')
4632 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004633 " Remove trailing "/"
4634 let dirname = substitute(dirname, "/$", "", "")
4635
4636 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4637 " returns the full path, including the word under the cursor, remove it
4638 if newdir =~ "/$" && newdir != "../"
4639 let dirname = fnamemodify(dirname, ":h")
4640 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004641 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004642 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004643 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004644 if has("win32")
4645 let dirname = substitute(dirname,'\\','/','ge')
4646 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004647 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004648 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004649
4650 " ignore <cr>s when done in the banner
4651 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004652 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004653 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004654 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004655 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004656 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004657 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004658 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004659 endif
4660 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004661 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004662
Bram Moolenaar446cb832008-06-24 21:56:24 +00004663 " set up o/s-dependent directory recognition pattern
4664 if has("amiga")
4665 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004666 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004667 let dirpat= '[\/]$'
4668 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004669
4670 if dirname !~ dirpat
4671 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004672 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004673 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004674 endif
4675
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004676 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004677 " ------------------------------
4678 " NetrwBrowseChgDir: edit a file {{{3
4679 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004680
Bram Moolenaar97d62492012-11-15 21:28:22 +01004681 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004682 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004683
Bram Moolenaar446cb832008-06-24 21:56:24 +00004684 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004685 if dirname =~ '/$'
4686 let dirname= dirname.newdir
4687 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004688 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004689 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004690 elseif newdir =~ '^\(/\|\a:\)'
4691 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004692 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004693 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004694 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004695 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004696 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004697 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004698 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004699 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004700 if type(g:netrw_browse_split) == 3
4701 " open file in server
4702 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004704 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004705
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004706 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004707 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004708 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4709 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004710 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004711 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004712 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004713 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004714
Bram Moolenaar446cb832008-06-24 21:56:24 +00004715 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004716 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004717 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4718 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004719 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004720 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004721 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004722 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004723
Bram Moolenaar446cb832008-06-24 21:56:24 +00004724 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004725 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004726 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004727 if !exists("b:netrw_curdir")
4728 let b:netrw_curdir= getcwd()
4729 endif
4730 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004731
Bram Moolenaar446cb832008-06-24 21:56:24 +00004732 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004733 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004734 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004735 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004736 return
4737 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004738 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004739
Bram Moolenaar9964e462007-05-05 17:54:07 +00004740 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004741 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004742 call s:NetrwMenu(0)
4743 " optional change to window
4744 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004745 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004746 " if g:netrw_chgwin is set to one more than the last window, then
4747 " vertically split the last window to make that window available.
4748 let curwin= winnr()
4749 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4750 vs
4751 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004752 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004753 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004755 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004756 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004757
Bram Moolenaar9964e462007-05-05 17:54:07 +00004758 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004759
Bram Moolenaar446cb832008-06-24 21:56:24 +00004760 " the point where netrw actually edits the (local) file
4761 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004762 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004763 if !&mod
4764 " if e the new file would fail due to &mod, then don't change any of the flags
4765 let dolockout= 1
4766 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004767 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004768 " some like c-^ to return to the last edited file
4769 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004770 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4771 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004772 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004773 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004774 if &hidden || &bufhidden == "hide"
4775 " file came from vim's hidden storage. Don't "restore" options with it.
4776 let dorestore= 0
4777 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004779 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004780
4781 " handle g:Netrw_funcref -- call external-to-netrw functions
4782 " This code will handle g:Netrw_funcref as an individual function reference
4783 " or as a list of function references. It will ignore anything that's not
4784 " a function reference. See :help Funcref for information about function references.
4785 if exists("g:Netrw_funcref")
4786 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004787 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004788 elseif type(g:Netrw_funcref) == 3
4789 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004790 if type(Fncref) == 2
4791 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004792 endif
4793 endfor
4794 endif
4795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004796 endif
4797
4798 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004799 " ----------------------------------------------------
4800 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4801 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004802 let dirname = newdir
4803 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004804 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004805 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004806
4807 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004808 " ---------------------------------------------
4809 " NetrwBrowseChgDir: refresh the directory list {{{3
4810 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004811 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004812 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813
4814 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004815 " --------------------------------------
4816 " NetrwBrowseChgDir: go up one directory {{{3
4817 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004818
4819 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4820 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004821 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004822 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823 endif
4824
4825 if has("amiga")
4826 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004827 if a:islocal
4828 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4829 let dirname= substitute(dirname,'/$','','')
4830 else
4831 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4832 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004833
Nir Lichtman1e34b952024-05-08 19:19:34 +02004834 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004835 " windows
4836 if a:islocal
4837 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4838 if dirname == ""
4839 let dirname= '/'
4840 endif
4841 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004842 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004843 endif
4844 if dirname =~ '^\a:$'
4845 let dirname= dirname.'/'
4846 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004847
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848 else
4849 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004850 if a:islocal
4851 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4852 if dirname == ""
4853 let dirname= '/'
4854 endif
4855 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004859 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004860 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861
4862 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004863 " --------------------------------------
4864 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4865 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004867 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004871 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004872 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004873 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874
4875 " search treedict for tree dir as-is
4876 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 let haskey= 1
4878 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004879 endif
4880
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004881 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 if has_key(w:netrw_treedict,treedir."/")
4884 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 let haskey = 1
4886 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004887 endif
4888 endif
4889
4890 " search treedict for treedir with any trailing / elided
4891 if !haskey && treedir =~ '/$'
4892 let treedir= substitute(treedir,'/$','','')
4893 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 let haskey = 1
4895 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004896 endif
4897 endif
4898
4899 if haskey
4900 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004902 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 else
4904 " go down one directory
4905 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004907 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004908 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909
4910 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004911 " ----------------------------------------
4912 " NetrwBrowseChgDir: Go down one directory {{{3
4913 " ----------------------------------------
4914 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004915 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004916 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004917 endif
4918
Bram Moolenaar97d62492012-11-15 21:28:22 +01004919 " --------------------------------------
4920 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4921 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004922 if dorestore
4923 " dorestore is zero'd when a local file was hidden or bufhidden;
4924 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004925 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004926 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004927 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004928 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004929 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004930 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004931 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004932 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004933 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004934 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004935 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004936
Bram Moolenaar446cb832008-06-24 21:56:24 +00004937 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004938endfun
4939
4940" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004941" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4942" for thin, long, and wide: cursor placed just after banner
4943" for tree, keeps cursor on current filename
4944fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004945 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4946 " this test needed because occasionally this function seems to be incorrectly called
4947 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004948 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004949 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004950 return
4951 endif
4952
Bram Moolenaara6878372014-03-22 21:02:50 +01004953 norm! 0
4954 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004955 let curline= getline(".")
4956 let swwline= winline() - 1
4957 if exists("w:netrw_treetop")
4958 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004959 elseif exists("b:netrw_curdir")
4960 let w:netrw_treetop= b:netrw_curdir
4961 else
4962 let w:netrw_treetop= getcwd()
4963 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004964 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004965 let curfile = getline(".")
4966 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004967 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004968 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004969 else
Tom Benham64a536d2024-11-07 21:15:03 +01004970 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004971 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004972 if w:netrw_treetop == '/'
4973 keepj call search('^\M'.curfile,"w")
4974 elseif curfile == '../'
4975 keepj call search('^\M'.curfile,"wb")
4976 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004977 while 1
4978 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4979 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004980 if treepath == curpath
4981 break
4982 endif
4983 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004984 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004985
Bram Moolenaara6878372014-03-22 21:02:50 +01004986 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004987 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004988 if exists("b:netrw_curdir")
4989 let curdir= b:netrw_curdir
4990 else
4991 let curdir= expand(getcwd())
4992 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004993 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004994 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004995 else
Tom Benham64a536d2024-11-07 21:15:03 +01004996 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004997 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004998 call s:RestorePosn(s:netrw_posn)
4999 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005000 let curdir= '\<'. escape(curdir, '~'). '/'
5001 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005002 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005003endfun
5004
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005005func s:redir()
5006 " set up redirection (avoids browser messages)
5007 " by default if not set, g:netrw_suppress_gx_mesg is true
5008 if get(g:, 'netrw_suppress_gx_mesg', 1)
5009 if &srr =~# "%s"
5010 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5011 else
5012 return &srr .. (has("win32") ? "nul" : "/dev/null")
5013 endif
5014 endif
5015 return ''
5016endfunc
5017
5018if has('unix')
5019 if has('win32unix')
5020 " Cygwin provides cygstart
5021 if executable('cygstart')
5022 fun! netrw#Launch(args)
5023 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5024 endfun
5025 elseif !empty($MSYSTEM) && executable('start')
5026 " MSYS2/Git Bash comes by default without cygstart; see
5027 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5028 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5029 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5030 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5031 fun! netrw#Launch(args)
5032 exe 'silent !start "" //b' a:args s:redir() | redraw!
5033 endfun
5034 else
5035 " imitate /usr/bin/start script for other environments and hope for the best
5036 fun! netrw#Launch(args)
5037 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5038 endfun
5039 endif
5040 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5041 fun! netrw#Launch(args)
5042 let args = a:args
5043 exe 'silent !' ..
5044 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
Konfekt460799d2024-11-14 21:42:27 +01005045 \ 'cmd.exe /c start /b ' .. args :
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005046 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5047 \ | redraw!
5048 endfun
5049 else
5050 fun! netrw#Launch(args)
Konfekteda923e2024-12-04 20:12:44 +01005051 exe ':silent ! nohup' a:args s:redir() (has('gui_running') ? '' : '&') | redraw!
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005052 endfun
5053 endif
5054elseif has('win32')
5055 fun! netrw#Launch(args)
5056 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5057 \ 'start "" /b' a:args s:redir() | redraw!
5058 endfun
5059else
5060 fun! netrw#Launch(dummy)
5061 echom 'No common launcher found'
5062 endfun
5063endif
5064
5065" Git Bash
5066if has('win32unix')
5067 " (cyg)start suffices
5068 let s:os_viewer = ''
5069" Windows / WSL
5070elseif executable('explorer.exe')
5071 let s:os_viewer = 'explorer.exe'
5072" Linux / BSD
5073elseif executable('xdg-open')
5074 let s:os_viewer = 'xdg-open'
5075" MacOS
5076elseif executable('open')
5077 let s:os_viewer = 'open'
5078endif
5079
5080fun! s:viewer()
Christian Brabandt92b36662024-12-08 09:52:37 +01005081 " g:netrw_browsex_viewer could be a string of program + its arguments,
5082 " test if first argument is executable
5083 if exists('g:netrw_browsex_viewer') && executable(split(g:netrw_browsex_viewer)[0])
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005084 " extract any viewing options. Assumes that they're set apart by spaces.
5085 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5086 if g:netrw_browsex_viewer =~ '\s'
5087 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5088 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5089 let oviewer = ''
5090 let cnt = 1
5091 while !executable(viewer) && viewer != oviewer
5092 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5093 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5094 let cnt = cnt + 1
5095 let oviewer = viewer
5096 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5097 endwhile
5098 else
5099 let viewer = g:netrw_browsex_viewer
5100 let viewopt = ""
5101 endif
5102 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5103 return viewer .. ' ' .. viewopt
5104 else
5105 if !exists('s:os_viewer')
5106 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5107 else
5108 return s:os_viewer
5109 endif
5110 endif
5111endfun
5112
5113fun! netrw#Open(file) abort
5114 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5115endf
5116
5117if !exists('g:netrw_regex_url')
5118 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5119endif
5120
Bram Moolenaara6878372014-03-22 21:02:50 +01005121" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005122" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005123" given filename; typically this means given their extension.
5124" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005125fun! netrw#BrowseX(fname,remote)
Konfekt460799d2024-11-14 21:42:27 +01005126 if a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
Bram Moolenaar91359012019-11-30 17:57:03 +01005127 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005128 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005129 endif
5130
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005131 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5132 let remote = a:remote
5133 else
5134 let remote = 0
5135 endif
5136
Bram Moolenaar97d62492012-11-15 21:28:22 +01005137 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005138 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005139
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005140 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5141 let awkeep = &aw
5142 set noaw
5143
Bram Moolenaar5c736222010-01-06 20:54:52 +01005144 " special core dump handler
5145 if a:fname =~ '/core\(\.\d\+\)\=$'
5146 if exists("g:Netrw_corehandler")
5147 if type(g:Netrw_corehandler) == 2
5148 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005149 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005150 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005151 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005152 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005153 if type(Fncref) == 2
5154 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005155 endif
5156 endfor
5157 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005158 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005159 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005160 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005161 return
5162 endif
5163 endif
5164
Bram Moolenaar446cb832008-06-24 21:56:24 +00005165 " set up the filename
5166 " (lower case the extension, make a local copy of a remote file)
5167 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005168 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005170 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005171 if exten =~ "[\\/]"
5172 let exten= ""
5173 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005175 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005177 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005178 call netrw#NetRead(3,a:fname)
5179 " attempt to rename tempfile
5180 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005181 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005182 if s:netrw_tmpfile != newname && newname != ""
5183 if rename(s:netrw_tmpfile,newname) == 0
5184 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005185 let fname= newname
5186 else
5187 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188 let fname= s:netrw_tmpfile
5189 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005190 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005191 let fname= s:netrw_tmpfile
5192 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005193 else
5194 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005195 " special ~ handler for local
5196 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005199 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005200
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005201 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5202 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005203
Bram Moolenaar446cb832008-06-24 21:56:24 +00005204 " cleanup: remove temporary file,
5205 " delete current buffer if success with handler,
5206 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005207 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005208 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005209" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005210" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005211" endif
5212
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005213 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005214 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005215 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005216 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005217 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005218 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005219 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005220 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005221 let @@ = ykeep
5222 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005223endfun
5224
5225" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005226" netrw#GX: gets word under cursor for gx support {{{2
5227" See also: netrw#BrowseXVis
5228" netrw#BrowseX
5229fun! netrw#GX()
5230" call Dfunc("netrw#GX()")
5231 if &ft == "netrw"
5232 let fname= s:NetrwGetWord()
5233 else
Konfekt3d7e5672024-10-27 22:16:49 +01005234 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005235 endif
5236" call Dret("netrw#GX <".fname.">")
5237 return fname
5238endfun
5239
Konfekt3d7e5672024-10-27 22:16:49 +01005240fun! s:GetURL() abort
5241 let URL = ''
5242 if exists('*Netrw_get_URL_' .. &filetype)
5243 let URL = call('Netrw_get_URL_' .. &filetype, [])
5244 endif
5245 if !empty(URL) | return URL | endif
5246 " URLs end in letter, digit or forward slash
5247 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5248 if !empty(URL) | return URL | endif
5249
5250 " Is it a file in the current work dir ...
5251 let file = expand("<cfile>")
5252 if filereadable(file) | return file | endif
5253 " ... or in that of the current buffer?
5254 let path = fnamemodify(expand('%'), ':p')
5255 if isdirectory(path)
5256 let dir = path
5257 elseif filereadable(path)
5258 let dir = fnamemodify(path, ':h')
5259 endif
5260 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5261
5262 return ''
5263endf
5264
Bram Moolenaar85850f32019-07-19 22:05:51 +02005265" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005266" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5267fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005268 let dict={}
5269 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005270 norm! gv"ay
5271 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005272 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005273 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005274endfun
5275
5276" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005277" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5278" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5279" to become an unlisted buffer, so in that case don't bwipe it.
5280fun! s:NetrwBufRename(newname)
5281" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5282" call Dredir("ls!","s:NetrwBufRename (before rename)")
5283 let oldbufname= bufname(bufnr("%"))
5284" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5285
5286 if oldbufname != a:newname
5287" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5288 let b:junk= 1
5289" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5290 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005291" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005292 let oldbufnr= bufnr(oldbufname)
5293" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5294" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5295 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5296" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5297 exe "bwipe! ".oldbufnr
5298" else " Decho
5299" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005300" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5301" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5302" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005303 endif
5304" call Dredir("ls!","s:NetrwBufRename (after rename)")
5305" else " Decho
5306" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5307 endif
5308
5309" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5310endfun
5311
5312" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005313" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005314fun! netrw#CheckIfRemote(...)
5315" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5316 if a:0 > 0
5317 let curfile= a:1
5318 else
5319 let curfile= expand("%")
5320 endif
5321" call Decho("curfile<".curfile.">")
5322 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005323" call Dret("netrw#CheckIfRemote 1")
5324 return 1
5325 else
5326" call Dret("netrw#CheckIfRemote 0")
5327 return 0
5328 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005329endfun
5330
5331" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005332" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5333fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005334 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005335 call inputsave()
5336 let newperm= input("Enter new permission: ")
5337 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005338 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5339 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 call system(chgperm)
5341 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005342 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 endif
5344 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005345 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005346 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005347 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005348endfun
5349
5350" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005351" s:CheckIfKde: checks if kdeinit is running {{{2
5352" Returns 0: kdeinit not running
5353" 1: kdeinit is running
5354fun! s:CheckIfKde()
5355" call Dfunc("s:CheckIfKde()")
5356 " seems kde systems often have gnome-open due to dependencies, even though
5357 " gnome-open's subsidiary display tools are largely absent. Kde systems
5358 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5359 if !exists("s:haskdeinit")
5360 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005361 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005362 if v:shell_error
5363 let s:haskdeinit = 0
5364 endif
5365 else
5366 let s:haskdeinit= 0
5367 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005368" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005369 endif
5370
5371" call Dret("s:CheckIfKde ".s:haskdeinit)
5372 return s:haskdeinit
5373endfun
5374
5375" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005376" s:NetrwClearExplore: clear explore variables (if any) {{{2
5377fun! s:NetrwClearExplore()
5378" call Dfunc("s:NetrwClearExplore()")
5379 2match none
5380 if exists("s:explore_match") |unlet s:explore_match |endif
5381 if exists("s:explore_indx") |unlet s:explore_indx |endif
5382 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5383 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5384 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5385 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5386 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5387 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5388 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5389" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005390" call Dret("s:NetrwClearExplore")
5391endfun
5392
5393" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005394" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5395fun! s:NetrwEditBuf(bufnum)
5396" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5397 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5398" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5399 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5400 else
5401" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005402 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005403 endif
5404" call Dret("s:NetrwEditBuf")
5405endfun
5406
5407" ---------------------------------------------------------------------
5408" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5409" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5410fun! s:NetrwEditFile(cmd,opt,fname)
5411" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5412 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5413" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5414 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5415 else
5416" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005417 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5418 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5419 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005420 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5421 endif
5422" call Dret("s:NetrwEditFile")
5423endfun
5424
5425" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005426" s:NetrwExploreListUniq: {{{2
5427fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005428 " this assumes that the list is already sorted
5429 let newexplist= []
5430 for member in a:explist
5431 if !exists("uniqmember") || member != uniqmember
5432 let uniqmember = member
5433 let newexplist = newexplist + [ member ]
5434 endif
5435 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005436 return newexplist
5437endfun
5438
5439" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005440" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5441fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005442 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005443 if a:newdir !~ '/$'
5444 " ok, looks like force is needed to get directory-style treatment
5445 if a:newdir =~ '@$'
5446 let newdir= substitute(a:newdir,'@$','/','')
5447 elseif a:newdir =~ '[*=|\\]$'
5448 let newdir= substitute(a:newdir,'.$','/','')
5449 else
5450 let newdir= a:newdir.'/'
5451 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005452 else
5453 " should already be getting treatment as a directory
5454 let newdir= a:newdir
5455 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005456 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005457 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005458 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005459endfun
5460
5461" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005462" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005463" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5464" expr : this is the expression to follow the directory. Will use s:ComposePath()
5465" pare =1: remove the current directory from the resulting glob() filelist
5466" =0: leave the current directory in the resulting glob() filelist
5467fun! s:NetrwGlob(direntry,expr,pare)
5468" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005469 if netrw#CheckIfRemote()
5470 keepalt 1sp
5471 keepalt enew
5472 let keep_liststyle = w:netrw_liststyle
5473 let w:netrw_liststyle = s:THINLIST
5474 if s:NetrwRemoteListing() == 0
5475 keepj keepalt %s@/@@
5476 let filelist= getline(1,$)
5477 q!
5478 else
5479 " remote listing error -- leave treedict unchanged
5480 let filelist= w:netrw_treedict[a:direntry]
5481 endif
5482 let w:netrw_liststyle= keep_liststyle
5483 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005484 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005485 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005486 " escape [ so it is not detected as wildcard character, see :h wildcard
5487 let path= substitute(path, '[', '[[]', 'g')
5488 endif
5489 if v:version > 704 || (v:version == 704 && has("patch656"))
5490 let filelist= glob(path,0,1,1)
5491 else
5492 let filelist= glob(path,0,1)
5493 endif
5494 if a:pare
5495 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5496 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005497 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005498 return filelist
5499endfun
5500
5501" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005502" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5503fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005504 if a:newfile =~ '[/@*=|\\]$'
5505 let newfile= substitute(a:newfile,'.$','','')
5506 else
5507 let newfile= a:newfile
5508 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005509 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005510 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005511 else
Tom Benham64a536d2024-11-07 21:15:03 +01005512 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005513 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005514endfun
5515
5516" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005517" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5518" and switches the hiding mode. The actual hiding is done by
5519" s:NetrwListHide().
5520" g:netrw_hide= 0: show all
5521" 1: show not-hidden files
5522" 2: show hidden files only
5523fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005524 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005525 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005526
5527 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005528
5529 " hide the files in the markfile list
5530 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5532 " remove fname from hiding list
5533 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5534 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5535 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005536 else
5537 " append fname to hiding list
5538 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5539 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5540 else
5541 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5542 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543 endif
5544 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005545 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 let g:netrw_hide= 1
5547
5548 else
5549
5550 " switch between show-all/show-not-hidden/show-hidden
5551 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005552 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005554 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005555 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005556 return
5557 endif
5558 endif
5559
Tom Benham64a536d2024-11-07 21:15:03 +01005560 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005561 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005562 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005563endfun
5564
5565" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005566" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5567fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005568 let ykeep= @@
5569 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005570 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005571
5572 " get new hiding list from user
5573 call inputsave()
5574 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5575 call inputrestore()
5576 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005577
5578 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005579 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005580
5581 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005582 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005583 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005584endfun
5585
5586" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005587" s:NetrwHidden: invoked by "gh" {{{2
5588fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005589 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005590 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005591 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005592
5593 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005594 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005595 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005596 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005597 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5598 else
5599 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5600 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005601 if g:netrw_list_hide =~ '^,'
5602 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5603 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005604
5605 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005606 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005607 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005608 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005609endfun
5610
5611" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005612" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5613fun! s:NetrwHome()
5614 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005615 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005616 else
5617 " go to vim plugin home
5618 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005619 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005620 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005621 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005622 let home= basehome."/.vim"
5623 break
5624 endif
5625 endfor
5626 if home == ""
5627 " just pick the first directory
5628 let home= substitute(&rtp,',.*$','','')
5629 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005630 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005631 let home= substitute(home,'/','\\','g')
5632 endif
5633 endif
5634 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005635 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005636" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005637 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005638" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005639 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005640 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005641" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005642 call mkdir(home)
5643 endif
5644 endif
5645 let g:netrw_home= home
5646 return home
5647endfun
5648
5649" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005650" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5651fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005652 if exists("s:netrwdrag")
5653 return
5654 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005655 if &ft != "netrw"
5656 return
5657 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005658
Bram Moolenaar97d62492012-11-15 21:28:22 +01005659 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005660 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005661 while getchar(0) != 0
5662 "clear the input stream
5663 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005664 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005665 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005666 let mouse_lnum = v:mouse_lnum
5667 let wlastline = line('w$')
5668 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005669 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5670 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005671 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005672 return
5673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005675 " 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 +01005676 " without this test when its disabled.
5677 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005678 if v:mouse_col > virtcol('.')
5679 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005680 return
5681 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005682
Bram Moolenaar446cb832008-06-24 21:56:24 +00005683 if a:islocal
5684 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005685 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005686 endif
5687 else
5688 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005689 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005690 endif
5691 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005692 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005693endfun
5694
5695" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005696" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5697fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005698 if &ft != "netrw"
5699 return
5700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005701 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005702endfun
5703
5704" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005705" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5706" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005707" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005708" a:islocal=2 : <c-r> used, remote
5709" a:islocal=3 : <c-r> used, local
5710fun! s:NetrwServerEdit(islocal,fname)
5711" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5712 let islocal = a:islocal%2 " =0: remote =1: local
5713 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5714
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005715 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005716 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005717 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005718 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005719 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005720 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5721 unlet s:netrw_browse_split_{winnr()}
5722 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005723 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005724 return
5725 endif
5726
5727 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005728
5729 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005730 let srvrname = g:netrw_browse_split[0]
5731 let tabnum = g:netrw_browse_split[1]
5732 let winnum = g:netrw_browse_split[2]
5733
5734 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005735 if !ctrlr
5736 " user must have closed the server window and the user did not use <c-r>, but
5737 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005738 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005739 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005740 endif
5741 let g:netrw_browse_split= 0
5742 if exists("s:netrw_browse_split_".winnr())
5743 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5744 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005745 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005746 return
5747
5748 elseif has("win32") && executable("start")
5749 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005750 call system("start gvim --servername ".srvrname)
5751
5752 else
5753 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005754 call system("gvim --servername ".srvrname)
5755 endif
5756 endif
5757
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005758 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5759 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005760 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005761 else
5762
5763 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5764
5765 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005766 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005767 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005768 endif
5769 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005770 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005771 return
5772
5773 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005774 if has("win32") && executable("start")
5775 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005776 call system("start gvim --servername ".g:netrw_servername)
5777 else
5778 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005779 call system("gvim --servername ".g:netrw_servername)
5780 endif
5781 endif
5782 endif
5783
5784 while 1
5785 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005786 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005787 break
5788 catch /^Vim\%((\a\+)\)\=:E241/
5789 sleep 200m
5790 endtry
5791 endwhile
5792
5793 if exists("g:netrw_browse_split")
5794 if type(g:netrw_browse_split) != 3
5795 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5796 endif
5797 unlet g:netrw_browse_split
5798 endif
5799 let g:netrw_browse_split= [g:netrw_servername,1,1]
5800 endif
5801
5802 else
5803 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5804 endif
5805
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005806endfun
5807
5808" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005809" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5810fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005811 if &ft != "netrw"
5812 return
5813 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005814" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005815
Bram Moolenaar8d043172014-01-23 14:24:41 +01005816 let s:ngw= s:NetrwGetWord()
5817 call s:NetrwMarkFile(a:islocal,s:ngw)
5818
5819" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005820endfun
5821
5822" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005823" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5824" Used to mark multiple files.
5825fun! s:NetrwSLeftdrag(islocal)
5826" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5827 if !exists("s:netrwdrag")
5828 let s:netrwdrag = winnr()
5829 if a:islocal
5830 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005831 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005832 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005833 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005834 endif
5835 let ngw = s:NetrwGetWord()
5836 if !exists("s:ngw") || s:ngw != ngw
5837 call s:NetrwMarkFile(a:islocal,ngw)
5838 endif
5839 let s:ngw= ngw
5840" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5841endfun
5842
5843" ---------------------------------------------------------------------
5844" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5845fun! s:NetrwSLeftrelease(islocal)
5846" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5847 if exists("s:netrwdrag")
5848 nunmap <s-leftrelease>
5849 let ngw = s:NetrwGetWord()
5850 if !exists("s:ngw") || s:ngw != ngw
5851 call s:NetrwMarkFile(a:islocal,ngw)
5852 endif
5853 if exists("s:ngw")
5854 unlet s:ngw
5855 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005856 unlet s:netrwdrag
5857 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005858" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005859endfun
5860
5861" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005862" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5863" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005865" 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 +02005866" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005867 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005868
5869 " 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 +02005870 " How-it-works: take the hiding command, convert it into a range.
5871 " Duplicate characters don't matter.
5872 " Remove all such characters from the '/~@#...890' string.
5873 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005874" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005876 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005877" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005878
5879 while listhide != ""
5880 if listhide =~ ','
5881 let hide = substitute(listhide,',.*$','','e')
5882 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5883 else
5884 let hide = listhide
5885 let listhide = ""
5886 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005887" 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 +01005888 if g:netrw_sort_by =~ '^[ts]'
5889 if hide =~ '^\^'
5890" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5891 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5892 elseif hide =~ '^\\(\^'
5893 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5894 endif
5895" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5896 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005897
5898 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005899" 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 +00005900 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005901" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005902 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005903 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005904" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005905 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005906 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005907" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005908 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005909
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005911 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005912" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005913 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005914" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005915 endif
5916
Bram Moolenaaradc21822011-04-01 18:03:16 +02005917 " remove any blank lines that have somehow remained.
5918 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005919 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005920
Bram Moolenaar97d62492012-11-15 21:28:22 +01005921 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005922" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923endfun
5924
5925" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005926" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005927" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005929
Bram Moolenaar97d62492012-11-15 21:28:22 +01005930 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005931 " get name of new directory from user. A bare <CR> will skip.
5932 " if its currently a directory, also request will be skipped, but with
5933 " a message.
5934 call inputsave()
5935 let newdirname= input("Please give directory name: ")
5936 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937
5938 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005939 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 return
5941 endif
5942
5943 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005944
5945 " Local mkdir:
5946 " sanity checks
5947 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005948 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005950 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005952 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953 return
5954 endif
5955 if s:FileReadable(fullnewdir)
5956 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005957 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005958 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005959 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005960 return
5961 endif
5962
5963 " requested new local directory is neither a pre-existing file or
5964 " directory, so make it!
5965 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005966 if has("unix")
5967 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5968 else
5969 call mkdir(fullnewdir,"p")
5970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005971 else
5972 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005973 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005974 return
5975 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005976 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005977 if v:shell_error != 0
5978 let @@= ykeep
5979 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005980 return
5981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005982 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005983 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984 return
5985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005986 endif
5987 endif
5988
5989 if v:shell_error == 0
5990 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005991 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005992 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005993 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005994 elseif !exists("g:netrw_quiet")
5995 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005997
5998 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005999 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00006000 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6001 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006002 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006003 if v:shell_error == 0
6004 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006005 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006006 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006007 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006008 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006009 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006010 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006011
6012 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006013 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006014 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006015 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006016 let remotepath= b:netrw_fname
6017 else
6018 let remotepath= ""
6019 endif
6020 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006021 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006022 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006023
Bram Moolenaar446cb832008-06-24 21:56:24 +00006024 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006025 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006026 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006027 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006028 let remotepath= b:netrw_fname
6029 else
6030 let remotepath= ""
6031 endif
6032 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006033 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006034 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 endif
6036
Bram Moolenaar97d62492012-11-15 21:28:22 +01006037 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006038endfun
6039
6040" ---------------------------------------------------------------------
6041" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6042fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006043 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6044 " its a tree-listing style
6045 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006046 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006047 let depth = strchars(substitute(curdepth,' ','','g'))
6048 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006049 if depth >= 2
6050 NetrwKeepj norm! 0
6051 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6052 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006053 elseif depth == 1
6054 NetrwKeepj norm! 0
6055 let treedepthchr= substitute(s:treedepthstring,' ','','')
6056 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006057 endif
6058 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006059 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006060 exe srch
6061 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006062 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006063endfun
6064
6065" ---------------------------------------------------------------------
6066" s:NetrwMaps: {{{2
6067fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006068
Bram Moolenaar85850f32019-07-19 22:05:51 +02006069 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006070 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006072 if !hasmapto("<Plug>NetrwReturn")
6073 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006074 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6075 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006076 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6077 endif
6078 endif
6079 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006080 endif
6081
Bram Moolenaar85850f32019-07-19 22:05:51 +02006082 " generate default <Plug> maps {{{3
6083 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006084 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006085 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6086 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6087 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6088 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6089 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6090 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6091 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6092 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6093 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6094 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006095
Bram Moolenaara6878372014-03-22 21:02:50 +01006096 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006097 " local normal-mode maps {{{3
6098 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6099 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6100 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6101 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6102 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6103 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6104 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006105 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006106 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6107 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6108 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6109" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6111 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6112 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006113 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006115 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6116 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6117 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6118 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006119 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6120 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6121 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6122 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6123 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6124 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6125 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6126 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6127 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6128 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6129 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6130 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6131 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006132 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006133 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006134 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6135 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6136 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6137 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6138 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006139 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006140 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006141 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006142 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006143 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6144 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6145 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006146 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006147 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006148 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6149 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006150 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006151 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6153 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6154 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006155 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,0),0)"<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006156 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006157
Tom Benham64a536d2024-11-07 21:15:03 +01006158 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,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006159 if !hasmapto('<Plug>NetrwHideEdit')
6160 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006161 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006162 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006163 if !hasmapto('<Plug>NetrwRefresh')
6164 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006165 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006166 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 : './',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006167 if s:didstarstar || !mapcheck("<s-down>","n")
6168 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006169 endif
6170 if s:didstarstar || !mapcheck("<s-up>","n")
6171 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006172 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006173 if !hasmapto('<Plug>NetrwTreeSqueeze')
6174 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006175 endif
6176 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006177 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6178 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006179 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6180 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6181 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6182 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6183 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6184 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6185 imap <buffer> <leftmouse> <Plug>ILeftmouse
6186 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006187 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6188 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6189 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6190 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6191 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006192 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006193 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6194 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006195 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006196 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6197 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6198 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6199 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6200 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6201 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6202 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006203 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6204
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006205 " support user-specified maps
6206 call netrw#UserMaps(1)
6207
Bram Moolenaar85850f32019-07-19 22:05:51 +02006208 else
6209 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006210 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006211 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6212 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6213 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6214 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6215 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6216 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6217 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006218 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6219 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006220 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6221 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6222" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006223 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6224 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6225 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6226 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6227 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6228 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6229 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6230 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006231 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006232 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006233 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6234 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6235 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6236 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6237 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6238 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6239 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6240 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6241 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6242 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6243 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006244 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006245 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006246 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6247 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6248 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6249 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6250 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006251 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6252 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006253 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006254 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006255 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006256 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6257 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006258 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006259 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,'./',0))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006260 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6261 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6262 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6263 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6264 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6265 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6266 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6267 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006268 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006269 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006270 if !hasmapto('<Plug>NetrwHideEdit')
6271 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006272 endif
6273 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6274 if !hasmapto('<Plug>NetrwRefresh')
6275 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006276 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006277 if !hasmapto('<Plug>NetrwTreeSqueeze')
6278 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006279 endif
6280 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006281
6282 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006283 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006284
Tom Benham64a536d2024-11-07 21:15:03 +01006285 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006286 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006287 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006288 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006289 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006290 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006291 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006292 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006293 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006294 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006295 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006296 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006297 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6298 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6299 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006300 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006301 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006302 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6303 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006304 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006305 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6306 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6307 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6308 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6309 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6310 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6311 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006312 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006313
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314 " support user-specified maps
6315 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006316 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006317endfun
6318
6319" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006320" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006321" If -buffer, the command is only available from within netrw buffers
6322" Otherwise, the command is available from any window, so long as netrw
6323" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006324fun! s:NetrwCommands(islocal)
6325" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6326
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006327 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6328 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006329 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 +01006330 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006332 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006333 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006334 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006335 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006336
6337" call Dret("s:NetrwCommands")
6338endfun
6339
6340" ---------------------------------------------------------------------
6341" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6342" glob()ing only works with local files
6343fun! s:NetrwMarkFiles(islocal,...)
6344" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006345 let curdir = s:NetrwGetCurdir(a:islocal)
6346 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006347 while i <= a:0
6348 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006349 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006350 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006351 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006352 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006353 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006354 else
6355 let mffiles= [a:{i}]
6356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006357" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006358 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006359" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006360 call s:NetrwMarkFile(a:islocal,mffile)
6361 endfor
6362 let i= i + 1
6363 endwhile
6364" call Dret("s:NetrwMarkFiles")
6365endfun
6366
6367" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006368" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006369fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006370 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006371 let curdir = s:NetrwGetCurdir(1)
6372 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006373 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006374 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6375 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006376 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006377 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006378 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6379 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006381 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006382 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006383endfun
6384
6385" ---------------------------------------------------------------------
6386" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6387" mark and unmark files. If a markfile list exists,
6388" then the rename and delete functions will use it instead
6389" of whatever may happen to be under the cursor at that
6390" moment. When the mouse and gui are available,
6391" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006392"
6393" Creates two lists
6394" s:netrwmarkfilelist -- holds complete paths to all marked files
6395" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6396"
6397" Creates a marked file match string
6398" s:netrwmarfilemtch_# -- used with 2match to display marked files
6399"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006400" Creates a buffer version of islocal
6401" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006402fun! s:NetrwMarkFile(islocal,fname)
6403" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006404" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006405
6406 " sanity check
6407 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006408" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006409 return
6410 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006411 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006412
Bram Moolenaar97d62492012-11-15 21:28:22 +01006413 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006414 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006415 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006416 if a:fname =~ '\a$'
6417 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6418 else
6419 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6420 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006421
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006423 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006424" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6425" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6426" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006427 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428
6429 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006430 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006432 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006433 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006434
6435 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006436 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006437" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006438 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6439 if s:netrwmarkfilelist_{curbufnr} == []
6440 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006442 call s:NetrwUnmarkList(curbufnr,curdir)
6443 else
6444 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006445" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006446 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006447 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006448 for fname in s:netrwmarkfilelist_{curbufnr}
6449 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006450 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006451 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006453 endif
6454 let first= 0
6455 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006456" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006457 endif
6458 endif
6459
6460 else
6461 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006462" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006463
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006464" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006465 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006466 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6467" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006468
6469 " build initial markfile matching pattern
6470 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006471 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006472 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006473 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006474 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006475" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006476 endif
6477
6478 " handle global markfilelist
6479 if exists("s:netrwmarkfilelist")
6480 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6481 if index(s:netrwmarkfilelist,dname) == -1
6482 " append new filename to global markfilelist
6483 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006484" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006485 else
6486 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006487" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6488" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006489 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006490" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006491 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006492" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006493 unlet s:netrwmarkfilelist
6494 endif
6495 endif
6496 else
6497 " initialize new global-directory markfilelist
6498 let s:netrwmarkfilelist= []
6499 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006500" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006501 endif
6502
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006504 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6505 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6506" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6507 if exists("g:did_drchip_netrwlist_syntax")
6508 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6509 endif
6510 else
6511" " call Decho("2match none",'~'.expand("<slnum>"))
6512 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006513 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006514 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006515 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006516" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6517" 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 +00006518endfun
6519
6520" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006521" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6522" mA: move the argument list to marked file list (tomflist=1)
6523" Uses the global marked file list
6524fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006525 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006526 let curdir = s:NetrwGetCurdir(a:islocal)
6527 let curbufnr = bufnr("%")
6528
6529 if a:tomflist
6530 " mA: move argument list to marked file list
6531 while argc()
6532 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006533 exe "argdel ".fnameescape(fname)
6534 call s:NetrwMarkFile(a:islocal,fname)
6535 endwhile
6536
6537 else
6538 " ma: move marked file list to argument list
6539 if exists("s:netrwmarkfilelist")
6540
6541 " for every filename in the marked list
6542 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006543 exe "argadd ".fnameescape(fname)
6544 endfor " for every file in the marked list
6545
6546 " unmark list and refresh
6547 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006548 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006549 NetrwKeepj call winrestview(svpos)
6550 endif
6551 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006552endfun
6553
6554" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006555" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6556" compress/decompress files using the programs
6557" in g:netrw_compress and g:netrw_uncompress,
6558" using g:netrw_compress_suffix to know which to
6559" do. By default:
6560" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006561" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006562fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006563 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006564 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006565 let curbufnr = bufnr("%")
6566
Bram Moolenaarff034192013-04-24 18:51:19 +02006567 " sanity check
6568 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006569 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006570 return
6571 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006572
Bram Moolenaar446cb832008-06-24 21:56:24 +00006573 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006574
6575 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006576 for fname in s:netrwmarkfilelist_{curbufnr}
Christian Brabandtcacfccf2024-11-23 13:28:01 +01006577 let sfx= substitute(fname,'^.\{-}\(\.[[:alnum:]]\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006578 if exists("g:netrw_decompress['".sfx."']")
6579 " fname has a suffix indicating that its compressed; apply associated decompression routine
6580 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006581 let exe= netrw#WinPath(exe)
6582 if a:islocal
6583 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006584 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006585 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006586 call system(exe." ".fname)
6587 if v:shell_error
6588 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006589 endif
6590 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006591 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6592 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006593 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006594
Bram Moolenaarff034192013-04-24 18:51:19 +02006595 endif
6596 unlet sfx
6597
Bram Moolenaar446cb832008-06-24 21:56:24 +00006598 if exists("exe")
6599 unlet exe
6600 elseif a:islocal
6601 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006603 if v:shell_error
6604 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6605 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006606 else
6607 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006609 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006610 endfor " for every file in the marked list
6611
Bram Moolenaar446cb832008-06-24 21:56:24 +00006612 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006613 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006615 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006616endfun
6617
6618" ---------------------------------------------------------------------
6619" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6620" If no marked files, then set up directory as the
6621" target. Currently does not support copying entire
6622" directories. Uses the local-buffer marked file list.
6623" Returns 1=success (used by NetrwMarkFileMove())
6624" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006625fun! s:NetrwMarkFileCopy(islocal,...)
6626" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6627
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006628 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006629 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 if b:netrw_curdir !~ '/$'
6631 if !exists("b:netrw_curdir")
6632 let b:netrw_curdir= curdir
6633 endif
6634 let b:netrw_curdir= b:netrw_curdir."/"
6635 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006636
Bram Moolenaarff034192013-04-24 18:51:19 +02006637 " sanity check
6638 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006639 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006640" call Dret("s:NetrwMarkFileCopy")
6641 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006642 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006644
Bram Moolenaar446cb832008-06-24 21:56:24 +00006645 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006646 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006647" call Dret("s:NetrwMarkFileCopy 0")
6648 return 0
6649 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006650" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006651
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006652 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006653 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006654" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006655 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006656 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6657" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6658 return
6659 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006660
6661 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006662 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006663 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6664 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006665" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006666 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006667 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6668 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006669" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006670 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006671 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006672 let oldname = a:1
6673 else
6674 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006676 let s:recursive= 1
6677 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6678 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6679 if ret == 0
6680 break
6681 endif
6682 endfor
6683 unlet s:recursive
6684 call s:NetrwUnmarkList(curbufnr,curdir)
6685" call Dret("s:NetrwMarkFileCopy ".ret)
6686 return ret
6687 endif
6688
6689 call inputsave()
6690 let newname= input("Copy ".oldname." to : ",oldname,"file")
6691 call inputrestore()
6692 if newname == ""
6693" call Dret("s:NetrwMarkFileCopy 0")
6694 return 0
6695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006696 let args= s:ShellEscape(oldname)
6697 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006698 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006699 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6700 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006701 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006702 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006703 let args= substitute(args,'/','\\','g')
6704 let tgt = substitute(tgt, '/','\\','g')
6705 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006706 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6707 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6708 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6709 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6710" call Decho("args <".args.">",'~'.expand("<slnum>"))
6711" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712 if isdirectory(s:NetrwFile(args))
6713" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006714 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006716 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006717 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6718 " contents to a target. One must append the source directory name to the target to get xcopy to
6719 " do the right thing.
6720 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006721" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006722 endif
6723 else
6724 let copycmd= g:netrw_localcopycmd
6725 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006726 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006727 let copycmd = substitute(copycmd,'\s.*$','','')
6728 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006729 let copycmd = netrw#WinPath(copycmd).copycmdargs
6730 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006731 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006733" call Decho("args <".args.">",'~'.expand("<slnum>"))
6734" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6735" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6736" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006737 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006738 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006739 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006740 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 +01006741 else
6742 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6743 endif
6744" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006745 return 0
6746 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006747
6748 elseif a:islocal && !s:netrwmftgt_islocal
6749 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006751 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006752
6753 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006754 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006756 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006757
6758 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006759 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006761 let curdir = getcwd()
6762 let tmpdir = s:GetTempfile("")
6763 if tmpdir !~ '/'
6764 let tmpdir= curdir."/".tmpdir
6765 endif
6766 if exists("*mkdir")
6767 call mkdir(tmpdir)
6768 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006769 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006770 if v:shell_error != 0
6771 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 +01006772" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006773 return
6774 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006776 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006777 if s:NetrwLcd(tmpdir)
6778" call Dret("s:NetrwMarkFileCopy : lcd failure")
6779 return
6780 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006781 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006782 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006783 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006784 if getcwd() == tmpdir
6785 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006786 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006787 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006788 if s:NetrwLcd(curdir)
6789" call Dret("s:NetrwMarkFileCopy : lcd failure")
6790 return
6791 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006792 if delete(tmpdir,"d")
6793 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006795 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006796 if s:NetrwLcd(curdir)
6797" call Dret("s:NetrwMarkFileCopy : lcd failure")
6798 return
6799 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006800 endif
6801 endif
6802 endif
6803
6804 " -------
6805 " cleanup
6806 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006807" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006808 " remove markings from local buffer
6809 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006810" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6811" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6812" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6813" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6814" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6815" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6816 if exists("s:recursive")
6817" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6818 else
6819" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006820 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006821 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006822 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006823 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006824 else
6825 " refresh local and targets for fast browsing
6826 if !exists("s:recursive")
6827 " remove markings from local buffer
6828" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6829 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6830 endif
6831
6832 " refresh buffers
6833 if s:netrwmftgt_islocal
6834" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6835 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6836 endif
6837 if a:islocal && s:netrwmftgt != curdir
6838" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6839 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6840 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006841 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842
Bram Moolenaar446cb832008-06-24 21:56:24 +00006843" call Dret("s:NetrwMarkFileCopy 1")
6844 return 1
6845endfun
6846
6847" ---------------------------------------------------------------------
6848" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6849" invoke vim's diff mode on the marked files.
6850" Either two or three files can be so handled.
6851" Uses the global marked file list.
6852fun! s:NetrwMarkFileDiff(islocal)
6853" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6854 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855
Bram Moolenaarff034192013-04-24 18:51:19 +02006856 " sanity check
6857 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006858 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006859" call Dret("s:NetrwMarkFileDiff")
6860 return
6861 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006862 let curdir= s:NetrwGetCurdir(a:islocal)
6863" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006864
Bram Moolenaara6878372014-03-22 21:02:50 +01006865 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006866 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006867 for fname in s:netrwmarkfilelist
6868 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006869 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006870" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006871 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872 diffthis
6873 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006874 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006876 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877 diffthis
6878 else
6879 break
6880 endif
6881 endfor
6882 call s:NetrwUnmarkList(curbufnr,curdir)
6883 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006884
Bram Moolenaar446cb832008-06-24 21:56:24 +00006885" call Dret("s:NetrwMarkFileDiff")
6886endfun
6887
6888" ---------------------------------------------------------------------
6889" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6890" Uses global markfilelist
6891fun! s:NetrwMarkFileEdit(islocal)
6892" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6893
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006894 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006895 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006896
6897 " sanity check
6898 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006899 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006900" call Dret("s:NetrwMarkFileEdit")
6901 return
6902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006903" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006904
Bram Moolenaar446cb832008-06-24 21:56:24 +00006905 if exists("s:netrwmarkfilelist_{curbufnr}")
6906 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006907 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 " unmark markedfile list
6909" call s:NetrwUnmarkList(curbufnr,curdir)
6910 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006912 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006914 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916" call Dret("s:NetrwMarkFileEdit")
6917endfun
6918
6919" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006920" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006921fun! s:NetrwMarkFileQFEL(islocal,qfel)
6922" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6923 call s:NetrwUnmarkAll()
6924 let curbufnr= bufnr("%")
6925
6926 if !empty(a:qfel)
6927 for entry in a:qfel
6928 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006929" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006930 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006931" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006932 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6933 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6934 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6935 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006937 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6938 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006939" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006940 endif
6941 endfor
6942 echo "(use me to edit marked files)"
6943 else
6944 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6945 endif
6946
6947" call Dret("s:NetrwMarkFileQFEL")
6948endfun
6949
6950" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006951" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6952" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6953" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6954fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006955 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006956 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957 let curbufnr = bufnr("%")
6958
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006959 if a:enbloc == 0
6960 " individually apply command to files, one at a time
6961 " sanity check
6962 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6963 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006964 return
6965 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006966
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006967 if exists("s:netrwmarkfilelist_{curbufnr}")
6968 " get the command
6969 call inputsave()
6970 let cmd= input("Enter command: ","","file")
6971 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006972 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006973 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006975
6976 " apply command to marked files, individually. Substitute: filename -> %
6977 " If no %, then append a space and the filename to the command
6978 for fname in s:netrwmarkfilelist_{curbufnr}
6979 if a:islocal
6980 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006981 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006982 endif
6983 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006984 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006985 endif
6986 if cmd =~ '%'
6987 let xcmd= substitute(cmd,'%',fname,'g')
6988 else
6989 let xcmd= cmd.' '.fname
6990 endif
6991 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006992 let ret= system(xcmd)
6993 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006994 let ret= s:RemoteSystem(xcmd)
6995 endif
6996 if v:shell_error < 0
6997 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6998 break
6999 else
yasudac75dad02024-08-22 21:06:32 +02007000 if ret !=# ''
7001 echo "\n"
7002 " skip trailing new line
7003 echo ret[0:-2]
7004 else
7005 echo ret
7006 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007007 endif
7008 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007009
7010 " unmark marked file list
7011 call s:NetrwUnmarkList(curbufnr,curdir)
7012
7013 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007014 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007015 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007016 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007017 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007018 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007019
7020 else " apply command to global list of files, en bloc
7021
7022 call inputsave()
7023 let cmd= input("Enter command: ","","file")
7024 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007025 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007026 return
7027 endif
7028 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007029 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007030 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007031 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007032 endif
7033 if a:islocal
7034 call system(cmd)
7035 if v:shell_error < 0
7036 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7037 endif
7038 else
7039 let ret= s:RemoteSystem(cmd)
7040 endif
7041 call s:NetrwUnmarkAll()
7042
7043 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007044 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007045 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007046
7047 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007048endfun
7049
7050" ---------------------------------------------------------------------
7051" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7052" as the marked file(s) (toggles suffix presence)
7053" Uses the local marked file list.
7054fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007055 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007056 let curbufnr = bufnr("%")
7057
7058 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7059 if exists("s:netrwmarkfilelist_{curbufnr}")
7060
7061 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007062 " construct suffix pattern
7063 if fname =~ '\.'
7064 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7065 else
7066 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7067 endif
7068 " determine if its in the hiding list or not
7069 let inhidelist= 0
7070 if g:netrw_list_hide != ""
7071 let itemnum = 0
7072 let hidelist= split(g:netrw_list_hide,',')
7073 for hidepat in hidelist
7074 if sfxpat == hidepat
7075 let inhidelist= 1
7076 break
7077 endif
7078 let itemnum= itemnum + 1
7079 endfor
7080 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007081 if inhidelist
7082 " remove sfxpat from list
7083 call remove(hidelist,itemnum)
7084 let g:netrw_list_hide= join(hidelist,",")
7085 elseif g:netrw_list_hide != ""
7086 " append sfxpat to non-empty list
7087 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7088 else
7089 " set hiding list to sfxpat
7090 let g:netrw_list_hide= sfxpat
7091 endif
7092 endfor
7093
7094 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007095 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007096 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007098 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007100endfun
7101
7102" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007103" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007104" Uses the local marked-file list.
7105fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007106 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007107 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007108 let curbufnr = bufnr("%")
7109
Bram Moolenaarff034192013-04-24 18:51:19 +02007110 " sanity check
7111 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007112 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007113 return
7114 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007115
Bram Moolenaar15146672011-10-20 22:22:38 +02007116 if exists("s:netrwmarkfilelist_{curbufnr}")
7117 " get the command
7118 call inputsave()
7119 let cmd= input("Enter vim command: ","","file")
7120 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007121 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007122 return
7123 endif
7124
7125 " apply command to marked files. Substitute: filename -> %
7126 " If no %, then append a space and the filename to the command
7127 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007128 if a:islocal
7129 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007130 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007131 exe cmd
7132 exe "sil! keepalt wq!"
7133 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007134 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007135 endif
7136 endfor
7137
7138 " unmark marked file list
7139 call s:NetrwUnmarkList(curbufnr,curdir)
7140
7141 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007142 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007143 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007144 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007145 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007146 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007147endfun
7148
7149" ---------------------------------------------------------------------
7150" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7151" as the marked file(s) (toggles suffix presence)
7152" Uses the local marked file list.
7153fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007154 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007155 let curbufnr = bufnr("%")
7156
7157 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7158 if exists("s:netrwmarkfilelist_{curbufnr}")
7159
7160 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007161 " construct suffix pattern
7162 if fname =~ '\.'
7163 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7164 else
7165 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7166 endif
7167 " determine if its in the hiding list or not
7168 let inhidelist= 0
7169 if g:netrw_list_hide != ""
7170 let itemnum = 0
7171 let hidelist= split(g:netrw_list_hide,',')
7172 for hidepat in hidelist
7173 if sfxpat == hidepat
7174 let inhidelist= 1
7175 break
7176 endif
7177 let itemnum= itemnum + 1
7178 endfor
7179 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007180 if inhidelist
7181 " remove sfxpat from list
7182 call remove(hidelist,itemnum)
7183 let g:netrw_list_hide= join(hidelist,",")
7184 elseif g:netrw_list_hide != ""
7185 " append sfxpat to non-empty list
7186 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7187 else
7188 " set hiding list to sfxpat
7189 let g:netrw_list_hide= sfxpat
7190 endif
7191 endfor
7192
7193 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007194 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007195 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007196 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007197 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007198 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007199endfun
7200
7201" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007202" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7203" Uses the global markfilelist
7204fun! s:NetrwMarkFileGrep(islocal)
7205" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007206 let svpos = winsaveview()
7207" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007208 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007209 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007210
7211 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007212" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007213 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007214" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007215 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007216 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 let netrwmarkfilelist= "*"
7219 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007220
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007222" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007223 call inputsave()
7224 let pat= input("Enter pattern: ","")
7225 call inputrestore()
7226 let patbang = ""
7227 if pat =~ '^!'
7228 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007229 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007230 endif
7231 if pat =~ '^\i'
7232 let pat = escape(pat,'/')
7233 let pat = '/'.pat.'/'
7234 else
7235 let nonisi = pat[0]
7236 endif
7237
7238 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007239" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007240 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007241 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007242 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007243 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007244" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7245 return
7246 endtry
7247 echo "(use :cn, :cp to navigate, :Rex to return)"
7248
7249 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007250" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7251 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007252
7253 if exists("nonisi")
7254 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007256 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007257 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007258 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007259 endif
7260
7261" call Dret("s:NetrwMarkFileGrep")
7262endfun
7263
7264" ---------------------------------------------------------------------
7265" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7266" uses the global marked file list
7267" s:netrwmfloc= 0: target directory is remote
7268" = 1: target directory is local
7269fun! s:NetrwMarkFileMove(islocal)
7270" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272 let curbufnr = bufnr("%")
7273
7274 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007275 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007277" call Dret("s:NetrwMarkFileMove")
7278 return
7279 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007280" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007281
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007283 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007284" call Dret("s:NetrwMarkFileCopy 0")
7285 return 0
7286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007287" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007288
7289 if a:islocal && s:netrwmftgt_islocal
7290 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007291" call Decho("move from local to local",'~'.expand("<slnum>"))
7292" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007293 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007294 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7295" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7296 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007298 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007299" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007300 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007301 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007302" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007303 if g:netrw_localmovecmd =~ '\s'
7304 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7305 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7306 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007307" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007308 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007309 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007310" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007311 endif
7312 else
7313 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007314" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007315 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007316 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007317 if g:netrw_keepdir
7318 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7319 let fname= b:netrw_curdir."/".fname
7320 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007321 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007322 let fname= substitute(fname,'/','\\','g')
7323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007324" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007325 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007326 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007327 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007328 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 +01007329 else
7330 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7331 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007332 break
7333 endif
7334 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007335
7336 elseif a:islocal && !s:netrwmftgt_islocal
7337 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007338" call Decho("move from local to remote",'~'.expand("<slnum>"))
7339" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007340 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007341 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007342" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007343 for fname in mflist
7344 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7345 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7346 endfor
7347 unlet mflist
7348
7349 elseif !a:islocal && s:netrwmftgt_islocal
7350 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007351" call Decho("move from remote to local",'~'.expand("<slnum>"))
7352" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007353 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007354 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007356 for fname in mflist
7357 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7358 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7359 endfor
7360 unlet mflist
7361
7362 elseif !a:islocal && !s:netrwmftgt_islocal
7363 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7365" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007366 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007367 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007368" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369 for fname in mflist
7370 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7371 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7372 endfor
7373 unlet mflist
7374 endif
7375
7376 " -------
7377 " cleanup
7378 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007379" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380
7381 " remove markings from local buffer
7382 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7383
7384 " refresh buffers
7385 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007387 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007388 endif
7389 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007392 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007393 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007394" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397
Bram Moolenaar446cb832008-06-24 21:56:24 +00007398" call Dret("s:NetrwMarkFileMove")
7399endfun
7400
7401" ---------------------------------------------------------------------
7402" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7403" using the hardcopy command. Local marked-file list only.
7404fun! s:NetrwMarkFilePrint(islocal)
7405" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7406 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007407
7408 " sanity check
7409 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007410 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007411" call Dret("s:NetrwMarkFilePrint")
7412 return
7413 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007414" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7415 let curdir= s:NetrwGetCurdir(a:islocal)
7416
Bram Moolenaar446cb832008-06-24 21:56:24 +00007417 if exists("s:netrwmarkfilelist_{curbufnr}")
7418 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007419 call s:NetrwUnmarkList(curbufnr,curdir)
7420 for fname in netrwmarkfilelist
7421 if a:islocal
7422 if g:netrw_keepdir
7423 let fname= s:ComposePath(curdir,fname)
7424 endif
7425 else
7426 let fname= curdir.fname
7427 endif
7428 1split
7429 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007430" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007431 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007432" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007433 hardcopy
7434 q
7435 endfor
7436 2match none
7437 endif
7438" call Dret("s:NetrwMarkFilePrint")
7439endfun
7440
7441" ---------------------------------------------------------------------
7442" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7443" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007444" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007445fun! s:NetrwMarkFileRegexp(islocal)
7446" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7447
7448 " get the regular expression
7449 call inputsave()
7450 let regexp= input("Enter regexp: ","","file")
7451 call inputrestore()
7452
7453 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007454 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007455" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007456 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007457" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007458 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007459 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007460 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461 else
7462 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007463 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007465" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007466
7467 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007468 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007469 if fname =~ '^'.fnameescape(curdir)
7470" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7471 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7472 else
7473" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7474 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7475 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007476 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007477
7478 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007479" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007480
7481 " convert displayed listing into a filelist
7482 let eikeep = &ei
7483 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007484 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007485 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007486" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007487 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007488 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007489 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007490 sil NetrwKeepj norm! "ap
7491 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007492 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007494 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007495 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007497 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007498 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007500 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007501 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007502 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7503 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007504 call histdel("/",-1)
7505 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506 endif
7507 " convert regexp into the more usual glob-style format
7508 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007509" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007511 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007512 let filelist= getline(1,line("$"))
7513 q!
7514 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516 endfor
7517 unlet filelist
7518 let @a = areg
7519 let &ei = eikeep
7520 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007521 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007522
7523" call Dret("s:NetrwMarkFileRegexp")
7524endfun
7525
7526" ---------------------------------------------------------------------
7527" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7528" Uses the local marked file list.
7529fun! s:NetrwMarkFileSource(islocal)
7530" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7531 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007532
7533 " sanity check
7534 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007535 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007536" call Dret("s:NetrwMarkFileSource")
7537 return
7538 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007539" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7540 let curdir= s:NetrwGetCurdir(a:islocal)
7541
Bram Moolenaar446cb832008-06-24 21:56:24 +00007542 if exists("s:netrwmarkfilelist_{curbufnr}")
7543 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007544 call s:NetrwUnmarkList(curbufnr,curdir)
7545 for fname in netrwmarkfilelist
7546 if a:islocal
7547 if g:netrw_keepdir
7548 let fname= s:ComposePath(curdir,fname)
7549 endif
7550 else
7551 let fname= curdir.fname
7552 endif
7553 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007555 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007556 endfor
7557 2match none
7558 endif
7559" call Dret("s:NetrwMarkFileSource")
7560endfun
7561
7562" ---------------------------------------------------------------------
7563" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7564" Uses the global markfilelist
7565fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007566 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007567 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007568 let curbufnr = bufnr("%")
7569
Bram Moolenaarff034192013-04-24 18:51:19 +02007570 " sanity check
7571 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007572 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007573 return
7574 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007575
Bram Moolenaar446cb832008-06-24 21:56:24 +00007576 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007577 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007578 call s:NetrwUnmarkAll()
7579
7580 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007581
Bram Moolenaar85850f32019-07-19 22:05:51 +02007582 call system(g:netrw_ctags." ".netrwmarkfilelist)
7583 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007584 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7585 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007586
Bram Moolenaar446cb832008-06-24 21:56:24 +00007587 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007588 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007589 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007590 let curdir= b:netrw_curdir
7591 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007592 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007593 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007594 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007595 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596 wq!
7597 endif
7598 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007599 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007600 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007601 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602endfun
7603
7604" ---------------------------------------------------------------------
7605" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007606" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007607" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007608" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007609" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007610fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007611 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007612 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007613 let hadtgt = exists("s:netrwmftgt")
7614 if !exists("w:netrw_bannercnt")
7615 let w:netrw_bannercnt= b:netrw_bannercnt
7616 endif
7617
7618 " set up target
7619 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007620 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7621 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007622 unlet s:netrwmftgt s:netrwmftgt_islocal
7623 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007624 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007625 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007626 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007627 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007628 return
7629 else
7630 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007631 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007632
7633 else
7634 " get word under cursor.
7635 " * If directory, use it for the target.
7636 " * If file, use b:netrw_curdir for the target
7637 let curword= s:NetrwGetWord()
7638 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007639 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007640 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007641 elseif !a:islocal && tgtdir =~ '/$'
7642 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007643 else
7644 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007645 endif
7646 endif
7647 if a:islocal
7648 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7649 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007650 endif
7651 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007653 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7654 endif
7655 let s:netrwmftgt_islocal= a:islocal
7656
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007657 " need to do refresh so that the banner will be updated
7658 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007659 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007660 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007661 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007662" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007663 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007664 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007665 else
Tom Benham64a536d2024-11-07 21:15:03 +01007666 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007667 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007668 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007669 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007670 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007671 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672endfun
7673
7674" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007675" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7676fun! s:NetrwGetCurdir(islocal)
7677" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7678
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007679 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007680 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7681" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7682 elseif !exists("b:netrw_curdir")
7683 let b:netrw_curdir= getcwd()
7684" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7685 endif
7686
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007687" 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 +01007688 if b:netrw_curdir !~ '\<\a\{3,}://'
7689 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007690" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007691 if g:netrw_keepdir == 0
7692 call s:NetrwLcd(curdir)
7693 endif
7694 endif
7695
7696" call Dret("s:NetrwGetCurdir <".curdir.">")
7697 return b:netrw_curdir
7698endfun
7699
7700" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007701" s:NetrwOpenFile: query user for a filename and open it {{{2
7702fun! s:NetrwOpenFile(islocal)
7703" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007704 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007705 call inputsave()
7706 let fname= input("Enter filename: ")
7707 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007708" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7709
7710 " determine if Lexplore is in use
7711 if exists("t:netrw_lexbufnr")
7712 " check if t:netrw_lexbufnr refers to a netrw window
7713" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7714 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7715 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7716" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7717 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7718 exe "NetrwKeepj e ".fnameescape(fname)
7719 let @@= ykeep
7720" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7721 endif
7722 endif
7723
7724 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007725 if fname !~ '[/\\]'
7726 if exists("b:netrw_curdir")
7727 if exists("g:netrw_quiet")
7728 let netrw_quiet_keep = g:netrw_quiet
7729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007730 let g:netrw_quiet = 1
7731 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007732 let s:rexposn_{bufnr("%")}= winsaveview()
7733" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007734 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007735 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007736 else
7737 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7738 endif
7739 if exists("netrw_quiet_keep")
7740 let g:netrw_quiet= netrw_quiet_keep
7741 else
7742 unlet g:netrw_quiet
7743 endif
7744 endif
7745 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007746 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007747 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007748 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007749" call Dret("s:NetrwOpenFile")
7750endfun
7751
7752" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007753" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7754" For the mapping to this function be made via
7755" netrwPlugin, you'll need to have had
7756" g:netrw_usetab set to non-zero.
7757fun! netrw#Shrink()
7758" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7759 let curwin = winnr()
7760 let wiwkeep = &wiw
7761 set wiw=1
7762
7763 if &ft == "netrw"
7764 if winwidth(0) > g:netrw_wiw
7765 let t:netrw_winwidth= winwidth(0)
7766 exe "vert resize ".g:netrw_wiw
7767 wincmd l
7768 if winnr() == curwin
7769 wincmd h
7770 endif
7771" call Decho("vert resize 0",'~'.expand("<slnum>"))
7772 else
7773 exe "vert resize ".t:netrw_winwidth
7774" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7775 endif
7776
7777 elseif exists("t:netrw_lexbufnr")
7778 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7779 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7780 let t:netrw_winwidth= winwidth(0)
7781 exe "vert resize ".g:netrw_wiw
7782 wincmd l
7783 if winnr() == curwin
7784 wincmd h
7785 endif
7786" call Decho("vert resize 0",'~'.expand("<slnum>"))
7787 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7788 exe "vert resize ".t:netrw_winwidth
7789" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007790 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791 call netrw#Lexplore(0,0)
7792 endif
7793
7794 else
7795 call netrw#Lexplore(0,0)
7796 endif
7797 let wiw= wiwkeep
7798
7799" call Dret("netrw#Shrink")
7800endfun
7801
7802" ---------------------------------------------------------------------
7803" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7804fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007805 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007806 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007807 call inputsave()
7808 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7809 call inputrestore()
7810
7811 " refresh the listing
7812 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007813 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007814 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816endfun
7817
7818" ---------------------------------------------------------------------
7819" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7820" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007821" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007822fun! s:NetrwUnmarkList(curbufnr,curdir)
7823" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7824
7825 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007826 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007827 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7828 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7829 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7830 call remove(s:netrwmarkfilelist,idx) " remove from global list
7831 endfor
7832 if s:netrwmarkfilelist == []
7833 unlet s:netrwmarkfilelist
7834 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007835
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836 " getting rid of the local marked-file lists is easy
7837 unlet s:netrwmarkfilelist_{a:curbufnr}
7838 endif
7839 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7840 unlet s:netrwmarkfilemtch_{a:curbufnr}
7841 endif
7842 2match none
7843" call Dret("s:NetrwUnmarkList")
7844endfun
7845
7846" ---------------------------------------------------------------------
7847" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7848fun! s:NetrwUnmarkAll()
7849" call Dfunc("s:NetrwUnmarkAll()")
7850 if exists("s:netrwmarkfilelist")
7851 unlet s:netrwmarkfilelist
7852 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007853 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007854 2match none
7855" call Dret("s:NetrwUnmarkAll")
7856endfun
7857
7858" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007859" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007860fun! s:NetrwUnmarkAll2()
7861" call Dfunc("s:NetrwUnmarkAll2()")
7862 redir => netrwmarkfilelist_let
7863 let
7864 redir END
7865 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007867 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7868 for flist in netrwmarkfilelist_list
7869 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7870 unlet s:netrwmarkfilelist_{curbufnr}
7871 unlet s:netrwmarkfilemtch_{curbufnr}
7872 endfor
7873" call Dret("s:NetrwUnmarkAll2")
7874endfun
7875
7876" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7878"
7879" Marked files are in two types of lists:
7880" s:netrwmarkfilelist -- holds complete paths to all marked files
7881" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7882"
7883" Marked files suitable for use with 2match are in:
7884" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007886 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007887 let curbufnr = bufnr("%")
7888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007889 " unmark marked file list
7890 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7891 if exists("s:netrwmarkfilelist")
7892" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007893 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007894 endif
7895
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007896 let ibuf= 1
7897 while ibuf < bufnr("$")
7898 if exists("s:netrwmarkfilelist_".ibuf)
7899 unlet s:netrwmarkfilelist_{ibuf}
7900 unlet s:netrwmarkfilemtch_{ibuf}
7901 endif
7902 let ibuf = ibuf + 1
7903 endwhile
7904 2match none
7905
Tom Benham64a536d2024-11-07 21:15:03 +01007906" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007907call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908endfun
7909
7910" ---------------------------------------------------------------------
7911" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7912fun! s:NetrwMenu(domenu)
7913
7914 if !exists("g:NetrwMenuPriority")
7915 let g:NetrwMenuPriority= 80
7916 endif
7917
Bram Moolenaaradc21822011-04-01 18:03:16 +02007918 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007919" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7920
7921 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007922" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007923 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007924 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7927 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7928 if g:netrw_dirhistmax > 0
7929 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7933 else
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7935 endif
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7943 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7944 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7945 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7946 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7947 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7948 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7949 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7950 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 +01007951 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 +02007952 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7953 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7954 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7955 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7956 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7957 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7958 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7959 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7960 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7961 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7962 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7963 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7964 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7965 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7966 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7967 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7968 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7969 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7970 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7971 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7972 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7973 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7974 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7975 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7976 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7977 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7978 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7979 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7980 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7981 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>'
7982 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>'
7983 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>'
7984 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7985 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>'
7986 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>'
7987 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 +01007988 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 +02007989 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7990 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007992 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7993 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007994
7995 elseif !a:domenu
7996 let s:netrwcnt = 0
7997 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007998 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007999 exe curwin."wincmd w"
8000
8001 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008002" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008003 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008005 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 endif
8007 endif
8008" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008009 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008010 endif
8011
8012endfun
8013
8014" ---------------------------------------------------------------------
8015" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8016" Used by the O maps (as <SID>NetrwObtain())
8017fun! s:NetrwObtain(islocal)
8018" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8019
Bram Moolenaar97d62492012-11-15 21:28:22 +01008020 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008022 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008023 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8025 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008026 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008028 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029
8030" call Dret("NetrwObtain")
8031endfun
8032
8033" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8035" If there's only one window, then the window will first be split.
8036" Returns:
8037" choice = 0 : didn't have to choose
8038" choice = 1 : saved modified file in window first
8039" choice = 2 : didn't save modified file, opened window
8040" choice = 3 : cancel open
8041fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008042 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008044 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045
8046 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008047 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008049 let curword = s:NetrwGetWord()
8050 let choice = 0
8051 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008053 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054
Bram Moolenaar8d043172014-01-23 14:24:41 +01008055 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056 if lastwinnr == 1
8057 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008058 " g:netrw_preview=0: preview window shown in a horizontally split window
8059 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008062 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008063 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008065 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008066 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008067 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008069 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070
8071 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008072 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008073 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008074 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008076
Bram Moolenaar71badf92023-04-22 22:40:14 +01008077 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8078 " whoops -- user trying to open file in the Lexplore window.
8079 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008080" exe g:netrw_chgwin."wincmd w"
8081 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008082 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008083 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008084
8085 " prevwinnr: the window number of the "prev" window
8086 " prevbufnr: the buffer number of the buffer in the "prev" window
8087 " bnrcnt : the qty of windows open on the "prev" buffer
8088 let prevwinnr = winnr()
8089 let prevbufnr = bufnr("%")
8090 let prevbufname = bufname("%")
8091 let prevmod = &mod
8092 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008093 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008094
8095 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096 " and it doesn't appear in any other extant window, then ask the
8097 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008098 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008099 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008100 exe prevwinnr."wincmd w"
8101
8102 if bnrcnt == 1 && &hidden == 0
8103 " only one copy of the modified buffer in a window, and
8104 " hidden not set, so overwriting will lose the modified file. Ask first...
8105 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008106 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008107
8108 if choice == 1
8109 " Yes -- write file & then browse
8110 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008111 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008113 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008114 exe origwin."wincmd w"
8115 let &ei = eikeep
8116 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117 return choice
8118 endif
8119
8120 elseif choice == 2
8121 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008122 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123
8124 else
8125 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008126 exe origwin."wincmd w"
8127 let &ei= eikeep
8128 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 return choice
8130 endif
8131 endif
8132 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008133 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008134 endif
8135
8136 " restore b:netrw_curdir (window split/enew may have lost it)
8137 let b:netrw_curdir= curdir
8138 if a:islocal < 2
8139 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008140 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008141 else
Tom Benham64a536d2024-11-07 21:15:03 +01008142 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008143 endif
8144 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008145 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 return choice
8147endfun
8148
8149" ---------------------------------------------------------------------
8150" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8151" Always assumed to be local -> remote
8152" call s:NetrwUpload(filename, target)
8153" call s:NetrwUpload(filename, target, fromdirectory)
8154fun! s:NetrwUpload(fname,tgt,...)
8155" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8156
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008157 if a:tgt =~ '^\a\{3,}://'
8158 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 else
8160 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8161 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008162" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008163
8164 if a:0 > 0
8165 let fromdir= a:1
8166 else
8167 let fromdir= getcwd()
8168 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008169" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008170
8171 if type(a:fname) == 1
8172 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008173" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008174 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008175" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8176 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8177" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178 if a:tgt =~ '/$'
8179 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008181 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008182 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008184 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 endif
8187 q!
8188
8189 elseif type(a:fname) == 3
8190 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 let curdir= getcwd()
8193 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008194 if s:NetrwLcd(fromdir)
8195" call Dret("s:NetrwUpload : lcd failure")
8196 return
8197 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008198 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200 if exists("g:netrw_port") && g:netrw_port != ""
8201 let useport= " ".g:netrw_scpport." ".g:netrw_port
8202 else
8203 let useport= ""
8204 endif
8205 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8206 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207 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 +02008208 if s:NetrwLcd(curdir)
8209" call Dret("s:NetrwUpload : lcd failure")
8210 return
8211 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008212
8213 elseif a:tgt =~ '^ftp:'
8214 call s:NetrwMethod(a:tgt)
8215
8216 if b:netrw_method == 2
8217 " handle uploading a list of files via ftp+.netrc
8218 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008219 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008220" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008221
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008222 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224
8225 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008226 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228 endif
8229
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008230 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008231" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008232
Bram Moolenaaradc21822011-04-01 18:03:16 +02008233 if tgtdir == ""
8234 let tgtdir= '/'
8235 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008236 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008238
8239 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008240 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8241" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008242 endfor
8243
8244 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245 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 +00008246 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008247" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8248 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008249 endif
8250 " 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 +01008251 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008252 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008253 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8254 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8255 else
8256 bw!|q
8257 endif
8258
8259 elseif b:netrw_method == 3
8260 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8261 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008262 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008263 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008264 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008265
8266 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008267 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008268" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008269 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008270 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008271" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008272 endif
8273
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008274 if exists("g:netrw_uid") && g:netrw_uid != ""
8275 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008276 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008277" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008278 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008279 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008281" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008282 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008283 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008284" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286 endif
8287
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008288 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008289" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008290
8291 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008293" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008294 endif
8295
8296 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008297 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008298" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008299 endif
8300
8301 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008302 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008303" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008304 endfor
8305
8306 " perform ftp:
8307 " -i : turns off interactive prompting from ftp
8308 " -n unix : DON'T use <.netrc>, even though it exists
8309 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008310 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008311 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008312 " 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 +01008313 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008314 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008315 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8316 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008317 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008318 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8319 let &debug = debugkeep
8320 let mod = 1
8321 else
8322 bw!|q
8323 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008324 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008325" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008326 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008327 endif
8328 else
8329 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8330 endif
8331 endif
8332
8333" call Dret("s:NetrwUpload")
8334endfun
8335
8336" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008337" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008338fun! s:NetrwPreview(path) range
8339" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008340" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8341" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008342 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008343 NetrwKeepj call s:NetrwOptionsSave("s:")
8344 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8345 NetrwKeepj call s:NetrwOptionsSafe(1)
8346 else
8347 NetrwKeepj call s:NetrwOptionsSafe(0)
8348 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008349 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008350" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008351 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008352" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8353 if g:netrw_preview
8354 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008355 let pvhkeep = &pvh
8356 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8357 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008358" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8359 else
8360 " horizontal split
8361 let pvhkeep = &pvh
8362 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8363 let &pvh = winheight(0) - winsz
8364" 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 +02008365 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008366 " g:netrw_preview g:netrw_alto
8367 " 1 : vert 1: top -- preview window is vertically split off and on the left
8368 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8369 " 0 : 1: top -- preview window is horizontally split off and on the top
8370 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8371 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008372 " 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 +02008373 " the BufEnter event set up in netrwPlugin.vim
8374" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8375 let eikeep = &ei
8376 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008377 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008378 let &ei= eikeep
8379" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008380 if exists("pvhkeep")
8381 let &pvh= pvhkeep
8382 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008383 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008384 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385 endif
8386 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008387 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 +00008388 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008389 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008390 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008391" call Dret("NetrwPreview")
8392endfun
8393
8394" ---------------------------------------------------------------------
8395" s:NetrwRefresh: {{{2
8396fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008397" 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 +00008398 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008399 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008400" call Decho("setl ma noro",'~'.expand("<slnum>"))
8401" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008402 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008403 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8404 if !exists("w:netrw_treetop")
8405 if exists("b:netrw_curdir")
8406 let w:netrw_treetop= b:netrw_curdir
8407 else
8408 let w:netrw_treetop= getcwd()
8409 endif
8410 endif
8411 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8412 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008413
8414 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008415 let screenposn = winsaveview()
8416" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008417
8418" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8419" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8420 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008422 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008424 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008426
8427 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008428" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8429 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430
8431 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008432 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8433 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8434" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8435 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8436 else
8437" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8438 2match none
8439 endif
8440 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441
Bram Moolenaar97d62492012-11-15 21:28:22 +01008442" restore
8443 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008444" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445endfun
8446
8447" ---------------------------------------------------------------------
8448" s:NetrwRefreshDir: refreshes a directory by name {{{2
8449" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008450" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008451fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 if g:netrw_fastbrowse == 0
8453 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455
8456 if tgtwin > 0
8457 " tgtwin is being displayed, so refresh it
8458 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008460 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008461 exe curwin."wincmd w"
8462
8463 elseif bufnr(a:dirname) > 0
8464 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008465 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008466 endif
8467
8468 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008469 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008470 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471endfun
8472
8473" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008474" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8475" window number to do its editing in.
8476" Supports [count]C where the count, if present, is used to specify
8477" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008478fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008479" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008480 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008481" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008482 if a:1 == "" " :NetrwC win#
8483 let g:netrw_chgwin= winnr()
8484 else " :NetrwC
8485 let g:netrw_chgwin= a:1
8486 endif
8487 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008488 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008489 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008490 let g:netrw_chgwin= winnr()
8491 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008492 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008493" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008494endfun
8495
8496" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8498" What this function does is to compute a priority for the patterns
8499" in the g:netrw_sort_sequence. It applies a substitute to any
8500" "files" that satisfy each pattern, putting the priority / in
8501" front. An "*" pattern handles the default priority.
8502fun! s:NetrwSetSort()
8503" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008504 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008505 if w:netrw_liststyle == s:LONGLIST
8506 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8507 else
8508 let seqlist = g:netrw_sort_sequence
8509 endif
8510 " sanity check -- insure that * appears somewhere
8511 if seqlist == ""
8512 let seqlist= '*'
8513 elseif seqlist !~ '\*'
8514 let seqlist= seqlist.',*'
8515 endif
8516 let priority = 1
8517 while seqlist != ""
8518 if seqlist =~ ','
8519 let seq = substitute(seqlist,',.*$','','e')
8520 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8521 else
8522 let seq = seqlist
8523 let seqlist = ""
8524 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008525 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008526 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008527 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008528 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008529 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008530 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008532" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008533
8534 " sanity check
8535 if w:netrw_bannercnt > line("$")
8536 " apparently no files were left after a Hiding pattern was used
8537" call Dret("SetSort : no files left after hiding")
8538 return
8539 endif
8540 if seq == '*'
8541 let starpriority= spriority
8542 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008543 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008544 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008545 " sometimes multiple sorting patterns will match the same file or directory.
8546 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008547 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8548 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008549 endif
8550 let priority = priority + 1
8551 endwhile
8552 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008553 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8554 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 endif
8556
8557 " Following line associated with priority -- items that satisfy a priority
8558 " pattern get prefixed by ###/ which permits easy sorting by priority.
8559 " Sometimes files can satisfy multiple priority patterns -- only the latest
8560 " priority pattern needs to be retained. So, at this point, these excess
8561 " priority prefixes need to be removed, but not directories that happen to
8562 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008563 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8564 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008565 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566
8567" call Dret("SetSort")
8568endfun
8569
Bram Moolenaarff034192013-04-24 18:51:19 +02008570" ---------------------------------------------------------------------
8571" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8572" Implements [count]Tb (bookhist<b>)
8573" [count]Th (bookhist<h>)
8574" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008575fun! s:NetrwSetTgt(islocal,bookhist,choice)
8576" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008577
8578 if a:bookhist == 'b'
8579 " supports choosing a bookmark as a target using a qb-generated list
8580 let choice= a:choice - 1
8581 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008582 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008583 else
8584 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8585 endif
8586
8587 elseif a:bookhist == 'h'
8588 " supports choosing a history stack entry as a target using a qb-generated list
8589 let choice= (a:choice % g:netrw_dirhistmax) + 1
8590 if exists("g:netrw_dirhist_".choice)
8591 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008592 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008593 else
8594 echomsg "Sorry, history#".a:choice." not available!"
8595 endif
8596 endif
8597
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008598 " refresh the display
8599 if !exists("b:netrw_curdir")
8600 let b:netrw_curdir= getcwd()
8601 endif
8602 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8603
Bram Moolenaarff034192013-04-24 18:51:19 +02008604" call Dret("s:NetrwSetTgt")
8605endfun
8606
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008608" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008610 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008611 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008613 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 +01008614 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008615 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008616 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008617endfun
8618
8619" ---------------------------------------------------------------------
8620" s:NetrwSplit: mode {{{2
8621" =0 : net and o
8622" =1 : net and t
8623" =2 : net and v
8624" =3 : local and o
8625" =4 : local and t
8626" =5 : local and v
8627fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628
Bram Moolenaar97d62492012-11-15 21:28:22 +01008629 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 call s:SaveWinVars()
8631
8632 if a:mode == 0
8633 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008634 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008635 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008636 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008638 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008639 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 unlet s:didsplit
8641
8642 elseif a:mode == 1
8643 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008644 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 tabnew
8646 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008647 NetrwKeepj call s:RestoreWinVars()
8648 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 unlet s:didsplit
8650
8651 elseif a:mode == 2
8652 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008653 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008654 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008655 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008656 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008657 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008658 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008659 unlet s:didsplit
8660
8661 elseif a:mode == 3
8662 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008663 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008664 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008665 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008667 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008668 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008669 unlet s:didsplit
8670
8671 elseif a:mode == 4
8672 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008673 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008674 let eikeep = &ei
8675 let netrw_winnr = winnr()
8676 let netrw_line = line(".")
8677 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008678 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008679 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008680 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008681 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8682 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008683 let &ei = eikeep
8684 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686 let b:netrw_curdir = netrw_curdir
8687 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008688 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008689 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008691 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008692 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8693 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694 let &ei= eikeep
8695 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008696 unlet s:didsplit
8697
8698 elseif a:mode == 5
8699 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008700 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008701 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008702 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008703 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008704 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008705 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706 unlet s:didsplit
8707
8708 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008709 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710 endif
8711
Bram Moolenaar97d62492012-11-15 21:28:22 +01008712 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713endfun
8714
8715" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008716" s:NetrwTgtMenu: {{{2
8717fun! s:NetrwTgtMenu()
8718 if !exists("s:netrw_menucnt")
8719 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008721" call Dfunc("s:NetrwTgtMenu()")
8722
8723 " the following test assures that gvim is running, has menus available, and has menus enabled.
8724 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8725 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008726" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008727 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8728 endif
8729 if !exists("s:netrw_initbookhist")
8730 call s:NetrwBookHistRead()
8731 endif
8732
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008733 " try to cull duplicate entries
8734 let tgtdict={}
8735
Bram Moolenaarff034192013-04-24 18:51:19 +02008736 " target bookmarked places
8737 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008738" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008739 let cnt= 1
8740 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008741 if has_key(tgtdict,bmd)
8742 let cnt= cnt + 1
8743 continue
8744 endif
8745 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008746 let ebmd= escape(bmd,g:netrw_menu_escape)
8747 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008748" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008749 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 +02008750 let cnt= cnt + 1
8751 endfor
8752 endif
8753
8754 " target directory browsing history
8755 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008756" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008757 let histcnt = 1
8758 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008759 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008760 if exists("g:netrw_dirhist_{histcnt}")
8761 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762 if has_key(tgtdict,histentry)
8763 let histcnt = histcnt + 1
8764 continue
8765 endif
8766 let tgtdict[histentry] = histcnt
8767 let ehistentry = escape(histentry,g:netrw_menu_escape)
8768" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008769 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 +02008770 endif
8771 let histcnt = histcnt + 1
8772 endwhile
8773 endif
8774 endif
8775" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776endfun
8777
8778" ---------------------------------------------------------------------
8779" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8780" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008781fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008782
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008783 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008784 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8785 let treedir= s:treedir
8786 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008787 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008788 return treedir
8789 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008790 if exists("s:prevwinopen")
8791 unlet s:prevwinopen
8792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793
Bram Moolenaar8d043172014-01-23 14:24:41 +01008794 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8795 let b:netrw_curdir= getcwd()
8796 endif
8797 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008798 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008799
8800 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008801
8802 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008803 let curline= substitute(getline('.'),"\t -->.*$",'','')
8804 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008805 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008806 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008807 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 else
8809 let treedir= ""
8810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811
8812 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008813 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008814 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816 return b:netrw_curdir
8817 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008818
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008819 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8820" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8821" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008822 if a:islocal && curline =~ '@$'
8823 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008824 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008825 let w:netrw_treetop = treedir
8826 endif
8827 else
8828 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8829 let treedir = s:NetrwTreePath(w:netrw_treetop)
8830 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008832
8833 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008834 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835 return treedir
8836endfun
8837
8838" ---------------------------------------------------------------------
8839" s:NetrwTreeDisplay: recursive tree display {{{2
8840fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008841 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008842 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843
8844 " install ../ and shortdir
8845 if a:depth == ""
8846 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008847 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008848 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 if a:dir == w:netrw_treetop
8850 let shortdir= a:dir
8851 else
8852 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8853 endif
8854 call setline(line("$")+1,a:depth.shortdir)
8855 else
8856 let shortdir= substitute(a:dir,'^.*/','','e')
8857 call setline(line("$")+1,a:depth.shortdir.'/')
8858 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008859 " append a / to dir if its missing one
8860 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861
8862 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008863 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864
Bram Moolenaar85850f32019-07-19 22:05:51 +02008865 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8866 if g:netrw_hide == 1
8867 " hide given patterns
8868 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008869 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008870 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008871 endfor
8872
8873 elseif g:netrw_hide == 2
8874 " show given patterns (only)
8875 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008876 let entries=[]
8877 for entry in w:netrw_treedict[dir]
8878 for pat in listhide
8879 if entry =~ pat
8880 call add(entries,entry)
8881 break
8882 endif
8883 endfor
8884 endfor
8885 let w:netrw_treedict[dir]= entries
8886 endif
8887 if depth != ""
8888 " always remove "." and ".." entries when there's depth
8889 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008890 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008891 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008892 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008893 endif
8894
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008895 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008896 if dir =~ '/$'
8897 let direntry= substitute(dir.entry,'[@/]$','','e')
8898 else
8899 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008904 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8905 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008906 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008908 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008909 endif
8910 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008911endfun
8912
8913" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008914" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8915fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008916 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008917 return
8918 endif
8919
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008920 for entry in w:netrw_treedict[a:dir]
8921 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008922
8923 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008924 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008925 let filelist = s:NetrwLocalListingList(direntry,0)
8926 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008927
8928 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008929 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008930 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8931 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008932
8933 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008934 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008935 let liststar = s:NetrwGlob(direntry.'/','*',1)
8936 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008937
8938 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008939 endif
8940 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008941endfun
8942
8943" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008944" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008945" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008946fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008947 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008948
8949 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008950 if !exists("w:netrw_treetop")
8951 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008952 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008953 " use \V in case the directory contains specials chars like '$' or '~'
8954 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8955 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008956 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008957 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008958 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008959 if exists("w:netrw_treetop")
8960 let s:netrw_treetop= w:netrw_treetop
8961 else
8962 let w:netrw_treetop= getcwd()
8963 let s:netrw_treetop= w:netrw_treetop
8964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008965
Bram Moolenaar446cb832008-06-24 21:56:24 +00008966 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008967 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968 let w:netrw_treedict= {}
8969 endif
8970
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008971 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008972 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008973 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008974 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008975
8976 " if past banner, record word
8977 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8978 let fname= expand("<cword>")
8979 else
8980 let fname= ""
8981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008982
8983 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008984 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008985
8986 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8987 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008988 1d
8989 endwhile
8990
Bram Moolenaar13600302014-05-22 18:26:40 +02008991 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008992
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008993 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994 endif
8995endfun
8996
8997" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008998" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008999" Normally, treetop is w:netrw_treetop, but a
9000" user of the function ( netrw#SetTreetop() )
9001" wipes that out prior to calling this function
9002fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009003" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9004 if line(".") < w:netrw_bannercnt + 2
9005 let treedir= a:treetop
9006 if treedir !~ '/$'
9007 let treedir= treedir.'/'
9008 endif
9009" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9010 return treedir
9011 endif
9012
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009013 let svpos = winsaveview()
9014" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009015 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009016" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009017 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009018" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9019 let curline= getline('.')
9020" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9021 if curline =~ '/$'
9022" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9023 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9024" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9025 elseif curline =~ '@\s\+-->'
9026" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9027 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9028 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9029" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009030 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009031" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009032 let treedir= ""
9033 endif
9034 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009035" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9036" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009037 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9038 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9039 let treedir= dirname.treedir
9040 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009041" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009042 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009043" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009044 if a:treetop =~ '/$'
9045 let treedir= a:treetop.treedir
9046 else
9047 let treedir= a:treetop.'/'.treedir
9048 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009049" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009050 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009051" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009052" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9053 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009054" call Dret("s:NetrwTreePath <".treedir.">")
9055 return treedir
9056endfun
9057
9058" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059" s:NetrwWideListing: {{{2
9060fun! s:NetrwWideListing()
9061
9062 if w:netrw_liststyle == s:WIDELIST
9063" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9064 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009065 " cpf: characters per filename
9066 " fpl: filenames per line
9067 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009068 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009069 let dict={}
9070 " save the unnamed register and register 0-9 and a
9071 let dict.a=[getreg('a'), getregtype('a')]
9072 for i in range(0, 9)
9073 let dict[i] = [getreg(i), getregtype(i)]
9074 endfor
9075 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009076" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 let b:netrw_cpf= 0
9078 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009079 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009080 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9081 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009082 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009083 " restore stored registers
9084 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085" call Dret("NetrwWideListing")
9086 return
9087 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009088 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009089 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009090" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009091
9092 " determine qty files per line (fpl)
9093 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9094 if w:netrw_fpl <= 0
9095 let w:netrw_fpl= 1
9096 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009097" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098
9099 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009100 " fpc: files per column of wide listing
9101 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009102 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009103 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9104 let newcolstart = w:netrw_bannercnt + fpc
9105 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009106" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009107 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009108" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009109 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009110 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 while line("$") >= newcolstart
9113 if newcolend > line("$") | let newcolend= line("$") | endif
9114 let newcolqty= newcolend - newcolstart
9115 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009116 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009117 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009118 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009119 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009120 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009121 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009122 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009123 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009124 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009125 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009126" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009127 if @* != keepregstar | sil! let @* = keepregstar | endif
9128 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009129 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009130 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9131 NetrwKeepj call histdel("/",-1)
9132 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9133 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009134" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009135 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009136 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009137" 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 +00009138" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009139 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009140 else
9141 if hasmapto("w","n")
9142 sil! nunmap <buffer> w
9143 endif
9144 if hasmapto("b","n")
9145 sil! nunmap <buffer> b
9146 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148endfun
9149
9150" ---------------------------------------------------------------------
9151" s:PerformListing: {{{2
9152fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009153" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9154" 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 +02009155" 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>"))
9156 sil! NetrwKeepj %d _
9157" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009158
Bram Moolenaar15146672011-10-20 22:22:38 +02009159 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009160" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009162
Bram Moolenaar85850f32019-07-19 22:05:51 +02009163 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009164 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009165" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166
9167" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009168" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009169" endif " Decho
9170
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009171" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9173 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009174" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9175 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176 endif
9177
9178 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009179 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009180
9181 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009182 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009183" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009184 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009185 if exists("g:netrw_pchk")
9186 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9187 " failure detections.
9188 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009189 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009190 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9191 endif
9192 if exists("g:netrw_pchk")
9193 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9194 else
9195 let curdir= b:netrw_curdir
9196 endif
9197 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9198 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9199 else
9200 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009201 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009202 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009203 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009204 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009205" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009206 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009207 let w:netrw_bannercnt= 1
9208 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009209" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9210" 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 +00009211
Bram Moolenaar85850f32019-07-19 22:05:51 +02009212 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009214 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215 let sortby= sortby." reversed"
9216 endif
9217
9218 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009219 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009220" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009221 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009222" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009223 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009224 NetrwKeepj put ='\" Sorted by '.sortby
9225 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009226 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9227 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009228" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009229 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009230 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009231 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9232 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009233 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009234" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009235" 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 +00009236 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009237
Bram Moolenaar85850f32019-07-19 22:05:51 +02009238 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009239 if g:netrw_banner
9240 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009241" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009242 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009243 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009245 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009246 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009247 endif
9248 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009250" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009252 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254
9255 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009256 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009257" 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 +01009258 if g:netrw_list_hide != "" && g:netrw_hide
9259 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009260 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009261 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009263 endif
9264 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009265 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009267
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009268" 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 +01009269 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009271 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009272" 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 +01009273 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009274 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009275" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009276" 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 +00009277 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278
9279 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009280 if g:netrw_banner
9281 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009282 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283" 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 +01009284" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009285" 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 +01009286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009289" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009291 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009292 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009293 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009294 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009295" 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 +01009296" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9297 return
9298 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009300
9301 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009302 if !exists("w:netrw_bannercnt")
9303 let w:netrw_bannercnt= 0
9304 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9306" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9307" 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 +01009308
Bram Moolenaar5c736222010-01-06 20:54:52 +01009309 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009310" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311" 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 +00009312 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009313 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009315 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009316" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009318 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009320" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009321 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322
Bram Moolenaar5c736222010-01-06 20:54:52 +01009323 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009324" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009325 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009326 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009327 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 else
9329 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009331 endif
9332 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009333
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009335" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009336 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9337 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009339 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009340 " exten: sort by extension
9341 " The histdel(...,-1) calls remove the last search from the search history
9342" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009343 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9344 NetrwKeepj call histdel("/",-1)
9345 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9346 NetrwKeepj call histdel("/",-1)
9347 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9348 NetrwKeepj call histdel("/",-1)
9349 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9350" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009351 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009352 " normal direction sorting
9353 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9354 else
9355 " reverse direction sorting
9356 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9357 endif
9358 endif
9359 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9360 NetrwKeepj call histdel("/",-1)
9361
Bram Moolenaar446cb832008-06-24 21:56:24 +00009362 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009363 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009365 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009367 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009368 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009370 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009371 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009372" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009373 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9374 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009376 endif
9377
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009378 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009380 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009381 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009382 call histdel("/",-1)
9383 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009384 endif
9385 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009386" 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 +00009387
9388 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9390" 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 +01009391 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392" 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 +01009393 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" 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 +00009395
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009396 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009397 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009399 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009400 endif
9401
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009402 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009403 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009404" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9405 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009406 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009407" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9408 else
9409" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9410" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9411" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9412" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009413 endif
9414
9415 " record previous current directory
9416 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009417" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009418
9419 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009420" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9421" 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 +01009422 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009423" 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 +02009424 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425" 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 +00009426
9427 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009428" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009429 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430" 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 +01009431 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009432" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009433 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9434 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009435" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009436" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009437
Bram Moolenaar8d043172014-01-23 14:24:41 +01009438 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9440" 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 +01009441" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9442 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443 unlet s:treecurpos
9444 endif
9445
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009446" 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>"))
9447" 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 +00009448" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9449endfun
9450
9451" ---------------------------------------------------------------------
9452" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009453fun! s:SetupNetrwStatusLine(statline)
9454" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9455
9456 if !exists("s:netrw_setup_statline")
9457 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009459
9460 if !exists("s:netrw_users_stl")
9461 let s:netrw_users_stl= &stl
9462 endif
9463 if !exists("s:netrw_users_ls")
9464 let s:netrw_users_ls= &laststatus
9465 endif
9466
9467 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009468 let dict={}
9469 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009470 redir @a
9471 try
9472 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009473 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009474 if &bg == "dark"
9475 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9476 else
9477 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9478 endif
9479 endtry
9480 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009481 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009482 endif
9483
9484 " set up status line (may use User9 highlighting)
9485 " insure that windows have a statusline
9486 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009487 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009488 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009489" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009490 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009491
9492" call Dret("SetupNetrwStatusLine : stl=".&stl)
9493endfun
9494
Bram Moolenaar85850f32019-07-19 22:05:51 +02009495" =========================================
9496" Remote Directory Browsing Support: {{{1
9497" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009498
9499" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009500" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9501" This function assumes that a long listing will be received. Size, time,
9502" and reverse sorts will be requested of the server but not otherwise
9503" enforced here.
9504fun! s:NetrwRemoteFtpCmd(path,listcmd)
9505" 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 +01009506" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009507 " sanity check: {{{3
9508 if !exists("w:netrw_method")
9509 if exists("b:netrw_method")
9510 let w:netrw_method= b:netrw_method
9511 else
9512 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9513" call Dret("NetrwRemoteFtpCmd")
9514 return
9515 endif
9516 endif
9517
9518 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9519 let ffkeep= &ff
9520 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009522
9523 " clear off any older non-banner lines " {{{3
9524 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009525" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9526 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009527
9528 ".........................................
9529 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9530 " ftp + <.netrc>: Method #2
9531 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009532 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009533 endif
9534 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009535 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009536" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009537 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009538 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009539" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009540 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009541" 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>"))
9542 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 +01009543 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009544" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9545 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 +01009546 endif
9547
9548 ".........................................
9549 elseif w:netrw_method == 3 " {{{3
9550 " ftp + machine,id,passwd,filename: Method #3
9551 setl ff=unix
9552 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009553 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009554 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009555 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009556 endif
9557
9558 " handle userid and password
9559 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009560" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009561 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9562 call NetUserPass("ftp:".host)
9563 endif
9564 if exists("g:netrw_uid") && g:netrw_uid != ""
9565 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009566 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009567 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009568 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009569 endif
9570 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009571 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009572 endif
9573 endif
9574
9575 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009576 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009577 endif
9578 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009579 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009580" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009581 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009582 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009583
9584 " perform ftp:
9585 " -i : turns off interactive prompting from ftp
9586 " -n unix : DON'T use <.netrc>, even though it exists
9587 " -n win32: quit being obnoxious about password
9588 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009589" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009590 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009591" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9593" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009594 endif
9595
9596 ".........................................
9597 elseif w:netrw_method == 9 " {{{3
9598 " sftp username@machine: Method #9
9599 " s:netrw_sftp_cmd
9600 setl ff=unix
9601
9602 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009603 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009604" call Dret("NetrwRemoteFtpCmd")
9605 return
9606
9607 ".........................................
9608 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009609 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009610 endif
9611
9612 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009613 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009614 sil! NetrwKeepj %s/\r$//e
9615 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009616 endif
9617 if a:listcmd == "dir"
9618 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009619 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9620 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9621 NetrwKeepj call histdel("/",-1)
9622 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009623 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 +01009624 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9625 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009626 endif
9627 endif
9628
9629 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9630 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009631 exe 'NetrwKeepj '.w:netrw_bannercnt
9632 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009633 endif
9634 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009635 exe 'NetrwKeepj '.w:netrw_bannercnt
9636 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009637 endif
9638
9639 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009640 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009641" call Dret("NetrwRemoteFtpCmd")
9642endfun
9643
9644" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009645" s:NetrwRemoteListing: {{{2
9646fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009647" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009648
Bram Moolenaara6878372014-03-22 21:02:50 +01009649 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9650 let w:netrw_bannercnt= s:bannercnt
9651 endif
9652 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009653 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009654 endif
9655
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009657
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 " sanity check:
9659 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009662" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 if !exists("g:netrw_quiet")
9664 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9665 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009666 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009667" call Dret("s:NetrwRemoteListing -1")
9668 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009669 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009670
Bram Moolenaar8d043172014-01-23 14:24:41 +01009671 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009672" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009674 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009675 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 +00009676 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009677 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 +00009678 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009679 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009680
Bram Moolenaar85850f32019-07-19 22:05:51 +02009681 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009682" call Dret("s:NetrwRemoteListing -1")
9683 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009685" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009686
Bram Moolenaar446cb832008-06-24 21:56:24 +00009687 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009688" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689 let w:netrw_method= b:netrw_method
9690 endif
9691
Bram Moolenaar13600302014-05-22 18:26:40 +02009692 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009693 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009694" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009695 let s:method = "ftp"
9696 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009697 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009699 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700 let listcmd= g:netrw_ftp_sizelist_cmd
9701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009702" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009704" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705
Bram Moolenaara6878372014-03-22 21:02:50 +01009706 " report on missing file or directory messages
9707 if search('[Nn]o such file or directory\|Failed to change directory')
9708 let mesg= getline(".")
9709 if exists("w:netrw_bannercnt")
9710 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009711 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009712 setl noma
9713 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009714 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009715 call netrw#ErrorMsg(s:WARNING,mesg,96)
9716" call Dret("s:NetrwRemoteListing : -1")
9717 return -1
9718 endif
9719
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009720 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 +00009721 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009723 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724
9725 " cleanup
9726 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009727 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9728 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009730 sil! NetrwKeepj %s/\r$//e
9731 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009732
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009733 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009734 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009735 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009736 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009737" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009740 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009741 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009742 exe "sil! NetrwKeepj ".line1
9743 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009744
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009746 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009747" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009748 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9749 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009751" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009752 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9753 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9754 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9755 NetrwKeepj call histdel("/",-1)
9756 NetrwKeepj call histdel("/",-1)
9757 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009758 endif
9759 endif
9760
Bram Moolenaar13600302014-05-22 18:26:40 +02009761 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009762 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009763" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009764 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009765" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009767" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9768 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009769 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009770 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9771 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9772 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9773 NetrwKeepj call histdel("/",-1)
9774 NetrwKeepj call histdel("/",-1)
9775 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009776 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009777 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9778 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 endif
9780 else
9781 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009782" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009783 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009785" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9786 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9787" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009788 endif
9789 endif
9790
9791 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009792 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009794 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9795 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796 endif
9797 endif
9798
9799 if w:netrw_liststyle == s:LONGLIST
9800 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009801" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802
9803 if s:method == "ftp"
9804 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009805 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009806 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009807 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009809 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009810 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009811 sil! NetrwKeepj 1
9812 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 let line2= line(".")
9814 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009816 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009817 endif
9818 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009819 exe "sil! NetrwKeepj ".line1
9820 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009821 endif
9822
9823 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009825 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 +00009826 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009827" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009828 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009830 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9831 NetrwKeepj call histdel("/",-1)
9832 NetrwKeepj call histdel("/",-1)
9833 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endif
9835 endif
9836
9837" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009838" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009840
9841" call Dret("s:NetrwRemoteListing 0")
9842 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009843endfun
9844
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845" ---------------------------------------------------------------------
9846" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9847fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009848 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009849
9850 let all= 0
9851 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9852 " remove all marked files
9853 for fname in s:netrwmarkfilelist_{bufnr("%")}
9854 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009855 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009857 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009858 let all= 1
9859 endif
9860 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009861 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009862
9863 else
9864 " remove files specified by range
9865
9866 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867 let keepsol = &l:sol
9868 setl nosol
9869 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870
9871 " remove multiple files and directories
9872 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009873 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009875 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009877 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878 let all= 1
9879 endif
9880 let ctr= ctr + 1
9881 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 endif
9884
9885 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009886 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009887 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888endfun
9889
9890" ---------------------------------------------------------------------
9891" s:NetrwRemoteRmFile: {{{2
9892fun! s:NetrwRemoteRmFile(path,rmfile,all)
9893" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9894
9895 let all= a:all
9896 let ok = ""
9897
9898 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9899 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009901 if !all
9902 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009904 call inputsave()
9905 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9906 call inputrestore()
9907 echohl NONE
9908 if ok == ""
9909 let ok="no"
9910 endif
9911 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009912 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009913 let all= 1
9914 endif
9915 endif
9916
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009917 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" 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 +00009919 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009920" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009921 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922 if path =~ '^\a\{3,}://'
9923 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009924 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009925 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9927 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009928" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009929 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009930" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009931 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009932 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933 let ok="q"
9934 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009935 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009936" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9937" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9938" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009944" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946 if v:shell_error != 0
9947 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009948 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 +01009949 else
9950 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9951 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009952 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009953 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009955" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956 endif
9957 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009958 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 endif
9961
9962 else
9963 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009964" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965 if !all
9966 call inputsave()
9967 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9968 call inputrestore()
9969 if ok == ""
9970 let ok="no"
9971 endif
9972 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009973 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974 let all= 1
9975 endif
9976 endif
9977
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009978 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 else
9982 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9984" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009985 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009986" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987
9988 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9990 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9991" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009992 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994
9995 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009996 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 endif
9998 endif
9999 endif
10000
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010001 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 endif
10004 endif
10005
10006" call Dret("s:NetrwRemoteRmFile ".ok)
10007 return ok
10008endfun
10009
10010" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011" s:NetrwRemoteRename: rename a remote file or directory {{{2
10012fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
10014 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010015 let svpos = winsaveview()
10016" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017 let ctr = a:firstline
10018 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10019
10020 " rename files given by the markfilelist
10021 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10022 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023 if exists("subfrom")
10024 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010025 else
10026 call inputsave()
10027 let newname= input("Moving ".oldname." to : ",oldname)
10028 call inputrestore()
10029 if newname =~ '^s/'
10030 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10031 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10032 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010033 endif
10034 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010037 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039 let oldname= s:ShellEscape(a:path.oldname)
10040 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010041 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042 endif
10043
10044 endfor
10045 call s:NetrwUnMarkFile(1)
10046
10047 else
10048
10049 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050 let keepsol= &l:sol
10051 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010052 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010054
10055 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056
10057 call inputsave()
10058 let newname= input("Moving ".oldname." to : ",oldname)
10059 call inputrestore()
10060
10061 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10062 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10063 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064 let oldname= s:ShellEscape(a:path.oldname)
10065 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010066 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010067 endif
10068
10069 let ctr= ctr + 1
10070 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010072 endif
10073
10074 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010075 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010076 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010077endfun
10078
Bram Moolenaar85850f32019-07-19 22:05:51 +020010079" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010080" Local Directory Browsing Support: {{{1
10081" ==========================================
10082
10083" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010084" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010085" Should accept: file://localhost/etc/fstab
10086" file:///etc/fstab
10087" file:///c:/WINDOWS/clock.avi
10088" file:///c|/WINDOWS/clock.avi
10089" file://localhost/c:/WINDOWS/clock.avi
10090" file://localhost/c|/WINDOWS/clock.avi
10091" file://c:/foo.txt
10092" file:///c:/foo.txt
10093" 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 +020010094fun! netrw#FileUrlEdit(fname)
10095" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010096 let fname = a:fname
10097 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010098" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010099 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010101 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010102 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010103 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010105 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010107 endif
10108 endif
10109 let fname2396 = netrw#RFC2396(fname)
10110 let fname2396e= fnameescape(fname2396)
10111 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010112 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010113" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010114 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010116 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10117 endif
10118 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010119
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10121" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010122 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010123 exe 'NetrwKeepj keepalt edit '.plainfname
10124 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10125
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" 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 +020010127" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010128 exe "sil doau BufReadPost ".fname2396e
10129endfun
10130
10131" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132" netrw#LocalBrowseCheck: {{{2
10133fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010134 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010135 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10136 "
10137 " unfortunate interaction -- split window debugging can't be used here, must use
10138 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10139 " another call to LocalBrowseCheck() when attempts to write
10140 " to the DBG buffer are made.
10141 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010142 " The &ft == "netrw" test was installed because the BufEnter event
10143 " would hit when re-entering netrw windows, creating unexpected
10144 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010145" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010146" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010148 " getting E930: Cannot use :redir inside execute
10149"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10151" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010152
Bram Moolenaar97d62492012-11-15 21:28:22 +010010153 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154 if isdirectory(s:NetrwFile(a:dirname))
10155" 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 +010010156
Bram Moolenaar97d62492012-11-15 21:28:22 +010010157 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10159" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010160 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010161
Bram Moolenaar446cb832008-06-24 21:56:24 +000010162 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010164 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010165
Bram Moolenaar5c736222010-01-06 20:54:52 +010010166 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010168 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010169 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010171" 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 +010010172" call Dret("netrw#LocalBrowseCheck")
10173 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010174 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010175
Bram Moolenaar85850f32019-07-19 22:05:51 +020010176 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010177 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10178 " AND IF the listing style is not a tree listing
10179 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010180" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010181 let ibuf = 1
10182 let buflast = bufnr("$")
10183 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010184 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10185 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010186 endif
10187 let ibuf= ibuf + 1
10188 endwhile
10189 endif
10190 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010191" 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>"))
10192" 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 +000010193 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010194" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010195endfun
10196
10197" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010198" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010199" performed any shell command. The idea is to cause all local-browsing
10200" buffers to be refreshed after a user has executed some shell command,
10201" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010202fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 " determine which buffers currently reside in a tab
10204 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010205 return
10206 endif
10207 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010208 return
10209 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010210 if !empty(getcmdwintype())
10211 " cannot move away from cmdline window, see :h E11
10212 return
10213 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010214 if exists("s:netrw_events") && s:netrw_events == 1
10215 " s:LocalFastBrowser gets called (indirectly) from a
10216 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010217 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010218 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010219 let itab = 1
10220 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010221 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010222 while itab <= tabpagenr("$")
10223 let buftablist = buftablist + tabpagebuflist()
10224 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010225 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010226 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010227 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10228 " | refresh any netrw window
10229 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010230 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010231 let ibl = 0
10232 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010233 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10234 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010235 " (ibuf not shown in a current window AND
10236 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010237 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010238 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010239 continue
10240 elseif index(tabpagebuflist(),ibuf) != -1
10241 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010242 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010243 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010244 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10245 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10246 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10247 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010248 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10249 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10250 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010251 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010252 endif
10253 let ibl= ibl + 1
10254 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010255 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010256 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010257endfun
10258
10259" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010260" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10261"
10262" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010263" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010264" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10265" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010266" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010267"
10268" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10269" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010270" (re-using a buffer may not be as accurate)
10271"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010272" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010273" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10274" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10275" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10276" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010277fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010278
10279 " initialize browselist, a list of buffer numbers that the local browser has used
10280 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010281 let s:netrw_browselist= []
10282 endif
10283
10284 " append current buffer to fastbrowse list
10285 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010286 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010287 endif
10288
10289 " enable autocmd events to handle refreshing/removing local browser buffers
10290 " If local browse buffer is currently showing: refresh it
10291 " If local browse buffer is currently hidden : wipe it
10292 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10293 " =1 : medium speed, re-use directory listing for remote only
10294 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10296 let s:netrw_events= 1
10297 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010298 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010299 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010300 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010301 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010302 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010303 endif
10304 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010305
10306 " user must have changed fastbrowse to its fast setting, so remove
10307 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010309 unlet s:netrw_events
10310 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010311 au!
10312 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010314 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010315endfun
10316
Tom Benham64a536d2024-11-07 21:15:03 +010010317fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010318 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010319 let dirname = a:dirname
10320 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010321 let filelist = s:NetrwGlob(dirname,"*",0)
10322 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010323
Nir Lichtman1e34b952024-05-08 19:19:34 +020010324 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010325 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010326 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010327 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010328 endif
10329
Tom Benham64a536d2024-11-07 21:15:03 +010010330 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010331 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10332 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010333 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010334
Tom Benham64a536d2024-11-07 21:15:03 +010010335 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010337
10338 if getftype(filename) == "link"
10339 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010340 let pfile= filename."@"
10341
10342 elseif getftype(filename) == "socket"
10343 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010344 let pfile= filename."="
10345
10346 elseif getftype(filename) == "fifo"
10347 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010348 let pfile= filename."|"
10349
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010350 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010351 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 let pfile= filename."/"
10353
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010354 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010355 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010356 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10357 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010358 let pfile= filename."*"
10359 else
10360 " normal file
10361 let pfile= filename
10362 endif
10363 elseif executable(filename)
10364 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010365 let pfile= filename."*"
10366 else
10367 " normal file
10368 let pfile= filename
10369 endif
10370
10371 else
10372 " normal file
10373 let pfile= filename
10374 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010375
10376 if pfile =~ '//$'
10377 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010378 endif
10379 let pfile= strpart(pfile,dirnamelen)
10380 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010381
10382 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010383 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10384 let sz = getfsize(filename)
10385 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10386 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010387
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010388 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010389 let sz= s:NetrwHumanReadable(sz)
10390 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010391 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010392 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010393 endif
10394
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010395 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010396 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010397 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010398 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010399 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010400 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010401 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010402
10403 elseif g:netrw_sort_by =~ "^s"
10404 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010405 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010406 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010407 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010408 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010409
10410 else
10411 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010412 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010413 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010414 endfor
10415
10416 return resultfilelist
10417endfun
10418
10419" ---------------------------------------------------------------------
10420" s:LocalListing: does the job of "ls" for local directories {{{2
10421fun! s:LocalListing()
10422
10423 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10424 for filename in filelist
10425 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010426 endfor
10427
10428 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010429 sil! NetrwKeepj g/^$/d
10430 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010431 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010432 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010433endfun
10434
10435" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010436" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10437fun! s:NetrwLocalExecute(cmd)
10438" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10439 let ykeep= @@
10440 " sanity check
10441 if !executable(a:cmd)
10442 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10443 let @@= ykeep
10444" call Dret("s:NetrwLocalExecute")
10445 return
10446 endif
10447
10448 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010450 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010451" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010452
10453 " strip any ansi escape sequences off
10454 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10455
10456 " show user the result(s)
10457 echomsg result
10458 let @@= ykeep
10459
10460" call Dret("s:NetrwLocalExecute")
10461endfun
10462
10463" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010464" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010465fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010466
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010467 if !exists("w:netrw_bannercnt")
10468 let w:netrw_bannercnt= b:netrw_bannercnt
10469 endif
10470
Bram Moolenaar97d62492012-11-15 21:28:22 +010010471 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010472 let ykeep = @@
10473 let ctr = a:firstline
10474 let svpos = winsaveview()
10475 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010476
10477 " rename files given by the markfilelist
10478 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10479 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010480 if exists("subfrom")
10481 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010482 else
10483 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010484 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010485 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486 if newname =~ ''
10487 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10488 let newname = substitute(newname,'^.*','','')
10489 elseif newname =~ ''
10490 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10491 let newname = substitute(newname,'[^/]*','','')
10492 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010493 if newname =~ '^s/'
10494 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10495 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010496 let newname = substitute(oldname,subfrom,subto,'')
10497 endif
10498 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010499 if !all && filereadable(newname)
10500 call inputsave()
10501 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10502 call inputrestore()
10503 if response == "all"
10504 let all= 1
10505 elseif response != "y" && response != "yes"
10506 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010507 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010508 NetrwKeepj call winrestview(svpos)
10509 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010510 return
10511 endif
10512 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010513 call rename(oldname,newname)
10514 endfor
10515 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010516
Bram Moolenaar97d62492012-11-15 21:28:22 +010010517 else
10518
10519 " attempt to rename files/directories
10520 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010521 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010522
10523 " sanity checks
10524 if line(".") < w:netrw_bannercnt
10525 let ctr= ctr + 1
10526 continue
10527 endif
10528 let curword= s:NetrwGetWord()
10529 if curword == "./" || curword == "../"
10530 let ctr= ctr + 1
10531 continue
10532 endif
10533
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010535 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010536
10537 call inputsave()
10538 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10539 call inputrestore()
10540
10541 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010542 let ctr= ctr + 1
10543 endwhile
10544 endif
10545
10546 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010547 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010548 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010549 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010550endfun
10551
10552" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553" s:NetrwLocalRm: {{{2
10554fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010555 if !exists("w:netrw_bannercnt")
10556 let w:netrw_bannercnt= b:netrw_bannercnt
10557 endif
10558
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010560 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 let ret = 0
10562 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010563 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564
10565 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10566 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 for fname in s:netrwmarkfilelist_{bufnr("%")}
10568 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010569 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010571 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572 let all= 1
10573 endif
10574 endfor
10575 call s:NetrwUnMarkFile(1)
10576
10577 else
10578 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010580 let keepsol= &l:sol
10581 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 let ctr = a:firstline
10583 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010584 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585
10586 " sanity checks
10587 if line(".") < w:netrw_bannercnt
10588 let ctr= ctr + 1
10589 continue
10590 endif
10591 let curword= s:NetrwGetWord()
10592 if curword == "./" || curword == "../"
10593 let ctr= ctr + 1
10594 continue
10595 endif
10596 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010597 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010599 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 let all= 1
10601 endif
10602 let ctr= ctr + 1
10603 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 endif
10606
10607 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010609 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010610 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010611 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010612 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010613endfun
10614
10615" ---------------------------------------------------------------------
10616" s:NetrwLocalRmFile: remove file fname given the path {{{2
10617" Give confirmation prompt unless all==1
10618fun! s:NetrwLocalRmFile(path,fname,all)
10619" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010620
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621 let all= a:all
10622 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010623 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010624 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010626
10627 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10628 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 if !all
10631 echohl Statement
10632 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010633 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 call inputrestore()
10635 echohl NONE
10636 if ok == ""
10637 let ok="no"
10638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010641" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010642 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 let all= 1
10644 endif
10645 endif
10646
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010647 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010648 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650 endif
10651
10652 else
10653 " attempt to remove directory
10654 if !all
10655 echohl Statement
10656 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010657 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 call inputrestore()
10659 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10660 if ok == ""
10661 let ok="no"
10662 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010663 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 let all= 1
10665 endif
10666 endif
10667 let rmfile= substitute(rmfile,'[\/]$','','e')
10668
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010669 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010670 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010671 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 endif
10673 endif
10674 endif
10675
10676" call Dret("s:NetrwLocalRmFile ".ok)
10677 return ok
10678endfun
10679
Bram Moolenaar85850f32019-07-19 22:05:51 +020010680" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010681" Support Functions: {{{1
10682
Bram Moolenaar488c6512005-08-11 20:09:58 +000010683" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010684" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10685" 0: marked file list of current buffer
10686" 1: marked file target
10687fun! netrw#Access(ilist)
10688 if a:ilist == 0
10689 if exists("s:netrwmarkfilelist_".bufnr('%'))
10690 return s:netrwmarkfilelist_{bufnr('%')}
10691 else
10692 return "no-list-buf#".bufnr('%')
10693 endif
10694 elseif a:ilist == 1
10695 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010696 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010697endfun
10698
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699" ---------------------------------------------------------------------
10700" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10701fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010702 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010703endfun
10704
Bram Moolenaara6878372014-03-22 21:02:50 +010010705" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010706" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10707" I expect this function to be used in
10708" :PChkAssert netrw#Expose("netrwmarkfilelist")
10709" for example.
10710fun! netrw#Expose(varname)
10711" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010712 if exists("s:".a:varname)
10713 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010714" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010715 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010716" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010717 if type(retval) == 3
10718 let retval = copy(retval)
10719 let i = 0
10720 while i < len(retval)
10721 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10722 let i = i + 1
10723 endwhile
10724 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010725" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010726 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010727 else
10728" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010729 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010730 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010731" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010732 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010733 endif
10734
10735" call Dret("netrw#Expose ".string(retval))
10736 return retval
10737endfun
10738
10739" ---------------------------------------------------------------------
10740" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10741fun! netrw#Modify(varname,newvalue)
10742" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10743 exe "let s:".a:varname."= ".string(a:newvalue)
10744" call Dret("netrw#Modify")
10745endfun
10746
10747" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010748" netrw#RFC2396: converts %xx into characters {{{2
10749fun! netrw#RFC2396(fname)
10750" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010751 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010752" call Dret("netrw#RFC2396 ".fname)
10753 return fname
10754endfun
10755
10756" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010757" netrw#UserMaps: supports user-specified maps {{{2
10758" see :help function()
10759"
10760" g:Netrw_UserMaps is a List with members such as:
10761" [[keymap sequence, function reference],...]
10762"
10763" The referenced function may return a string,
10764" refresh : refresh the display
10765" -other- : this string will be executed
10766" or it may return a List of strings.
10767"
10768" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010769" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010770" Related functions:
10771" netrw#Expose(varname) -- see s:varname variables
10772" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10773" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10774fun! netrw#UserMaps(islocal)
10775" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10776" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10777
10778 " set up usermaplist
10779 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10780" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10781 for umap in g:Netrw_UserMaps
10782" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10783" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10784 " if umap[0] is a string and umap[1] is a string holding a function name
10785 if type(umap[0]) == 1 && type(umap[1]) == 1
10786" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10787 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10788 else
10789 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10790 endif
10791 endfor
10792 endif
10793" call Dret("netrw#UserMaps")
10794endfun
10795
10796" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010797" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10798fun! netrw#WinPath(path)
10799" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010800 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010801 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010802 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010803 " remove trailing slash (Win95)
10804 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10805 " remove escaped spaces
10806 let path = substitute(path, '\ ', ' ', 'g')
10807 " convert slashes to backslashes
10808 let path = substitute(path, '/', '\', 'g')
10809 else
10810 let path= a:path
10811 endif
10812" call Dret("netrw#WinPath <".path.">")
10813 return path
10814endfun
10815
10816" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010817" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10818fun! s:StripTrailingSlash(path)
10819 " remove trailing slash
10820 return substitute(a:path, '[/\\]$', '', 'g')
10821endfun
10822
Travis Sheltone34d0e32024-07-30 21:08:56 +020010823" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010824" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10825" cb : bl2mf=0 add marked files to buffer list
10826" cB : bl2mf=1 use bufferlist to mark files
10827" (mnemonic: cb = copy (marked files) to buffer list)
10828fun! s:NetrwBadd(islocal,bl2mf)
10829" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10830 if a:bl2mf
10831 " cB: add buffer list to marked files
10832 redir => bufl
10833 ls
10834 redir END
10835 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10836 for fname in bufl
10837 call s:NetrwMarkFile(a:islocal,fname)
10838 endfor
10839 else
10840 " cb: add marked files to buffer list
10841 for fname in s:netrwmarkfilelist_{bufnr("%")}
10842" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10843 exe "badd ".fnameescape(fname)
10844 endfor
10845 let curbufnr = bufnr("%")
10846 let curdir = s:NetrwGetCurdir(a:islocal)
10847 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10848 endif
10849" call Dret("s:NetrwBadd")
10850endfun
10851
10852" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010853" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10854fun! s:ComposePath(base,subdir)
10855" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10856
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010857 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010859 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010860 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010861 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010862 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010863 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010864 endif
10865
Bram Moolenaar85850f32019-07-19 22:05:51 +020010866 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010867 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010869 let ret= a:subdir
10870
Nir Lichtman1e34b952024-05-08 19:19:34 +020010871 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010873 if a:base =~ '[/\\]$'
10874 let ret= a:base.a:subdir
10875 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010877 endif
10878
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879 elseif a:base =~ '^\a\{3,}://'
10880" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010881 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10882 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10883 if a:subdir == '../'
10884 if curpath =~ '[^/]/[^/]\+/$'
10885 let curpath= substitute(curpath,'[^/]\+/$','','')
10886 else
10887 let curpath=""
10888 endif
10889 let ret= urlbase.curpath
10890 else
10891 let ret= urlbase.curpath.a:subdir
10892 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10894" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10895" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010896
10897 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010898" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010899 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10900 if a:base =~ '^//'
10901 " keeping initial '//' for the benefit of network share listing support
10902 let ret= '/'.ret
10903 endif
10904 let ret= simplify(ret)
10905 endif
10906
10907" call Dret("s:ComposePath ".ret)
10908 return ret
10909endfun
10910
10911" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010912" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10913" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10914fun! s:DeleteBookmark(fname)
10915" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10916 call s:MergeBookmarks()
10917
10918 if exists("g:netrw_bookmarklist")
10919 let indx= index(g:netrw_bookmarklist,a:fname)
10920 if indx == -1
10921 let indx= 0
10922 while indx < len(g:netrw_bookmarklist)
10923 if g:netrw_bookmarklist[indx] =~ a:fname
10924 call remove(g:netrw_bookmarklist,indx)
10925 let indx= indx - 1
10926 endif
10927 let indx= indx + 1
10928 endwhile
10929 else
10930 " remove exact match
10931 call remove(g:netrw_bookmarklist,indx)
10932 endif
10933 endif
10934
10935" call Dret("s:DeleteBookmark")
10936endfun
10937
10938" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010939" s:FileReadable: o/s independent filereadable {{{2
10940fun! s:FileReadable(fname)
10941" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10942
10943 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010944 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010945 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010946 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010947 endif
10948
10949" call Dret("s:FileReadable ".ret)
10950 return ret
10951endfun
10952
10953" ---------------------------------------------------------------------
10954" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10955" Places correct suffix on end of temporary filename,
10956" using the suffix provided with fname
10957fun! s:GetTempfile(fname)
10958" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10959
10960 if !exists("b:netrw_tmpfile")
10961 " get a brand new temporary filename
10962 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010964
Bram Moolenaarc236c162008-07-13 17:41:49 +000010965 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010967
Bram Moolenaar9964e462007-05-05 17:54:07 +000010968 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010969 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10970" 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 +010010971 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010972" call Dret("s:GetTempfile getcwd<".getcwd().">")
10973 return ""
10974 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975
Bram Moolenaar9964e462007-05-05 17:54:07 +000010976 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010977 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010978" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979
Bram Moolenaar9964e462007-05-05 17:54:07 +000010980 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010982 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010983 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 if !exists("+shellslash") || !&ssl
10985 let tmpfile = substitute(tmpfile,'/','\','g')
10986 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010987 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010989 endif
10990 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010992 else
10993 " re-use temporary filename
10994 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010996 endif
10997
10998 " use fname's suffix for the temporary file
10999 if a:fname != ""
11000 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011001" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011002 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011003 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011004 elseif a:fname =~ '.txz$'
11005 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011006 else
11007 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11008 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011009" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011010 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011012 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011014 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11015 endif
11016 endif
11017
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011018" 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 +000011019" call Dret("s:GetTempfile <".tmpfile.">")
11020 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011021endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011022
11023" ---------------------------------------------------------------------
11024" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011025" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011026fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011027" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011028 if s:user == ""
11029 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11030 else
11031 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11032 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011033 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011034 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011035 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011036 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011037 else
11038 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11039 endif
11040" call Dret("s:MakeSshCmd <".sshcmd.">")
11041 return sshcmd
11042endfun
11043
11044" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011045" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11046fun! s:MakeBookmark(fname)
11047" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11048
11049 if !exists("g:netrw_bookmarklist")
11050 let g:netrw_bookmarklist= []
11051 endif
11052
11053 if index(g:netrw_bookmarklist,a:fname) == -1
11054 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011055 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011056 call add(g:netrw_bookmarklist,a:fname.'/')
11057 elseif a:fname !~ '/'
11058 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11059 else
11060 call add(g:netrw_bookmarklist,a:fname)
11061 endif
11062 call sort(g:netrw_bookmarklist)
11063 endif
11064
11065" call Dret("s:MakeBookmark")
11066endfun
11067
11068" ---------------------------------------------------------------------
11069" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11070fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011071" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011072 " get bookmarks from .netrwbook file
11073 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011074 if filereadable(s:NetrwFile(savefile))
11075" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011076 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011077" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011078 NetrwKeepj call delete(savefile)
11079 endif
11080" call Dret("s:MergeBookmarks")
11081endfun
11082
11083" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011084" s:NetrwBMShow: {{{2
11085fun! s:NetrwBMShow()
11086" call Dfunc("s:NetrwBMShow()")
11087 redir => bmshowraw
11088 menu
11089 redir END
11090 let bmshowlist = split(bmshowraw,'\n')
11091 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011092 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011093 if bmshowfuncs != []
11094 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011095 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011096 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011097 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011099 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011100" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11101endfun
11102
11103" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011104" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011105fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011106 if !exists("w:netrw_liststyle")
11107 let w:netrw_liststyle= g:netrw_liststyle
11108 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011109" 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 +020011110
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011111" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11112
Bram Moolenaaradc21822011-04-01 18:03:16 +020011113 if &ft != "netrw"
11114 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11115 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011117
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011118 elseif g:netrw_cursor == 8
11119 if w:netrw_liststyle == s:WIDELIST
11120 setl cursorline
11121 setl cursorcolumn
11122 else
11123 setl cursorline
11124 endif
11125 elseif g:netrw_cursor == 7
11126 setl cursorline
11127 elseif g:netrw_cursor == 6
11128 if w:netrw_liststyle == s:WIDELIST
11129 setl cursorline
11130 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011131 elseif g:netrw_cursor == 4
11132 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011133" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011134 setl cursorline
11135 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011136
11137 elseif g:netrw_cursor == 3
11138 " thin-long-tree: cursorline, user's cursorcolumn
11139 " wide : cursorline, cursorcolumn
11140 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011141" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011142 setl cursorline
11143 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145" 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 +020011146 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011147 endif
11148
11149 elseif g:netrw_cursor == 2
11150 " thin-long-tree: cursorline, user's cursorcolumn
11151 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011153 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011154
11155 elseif g:netrw_cursor == 1
11156 " thin-long-tree: user's cursorline, user's cursorcolumn
11157 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011158 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011159" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011160 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011161 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011162" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011163 endif
11164
11165 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011166 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011168 let &l:cursorline = s:netrw_usercul
11169 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011170 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011171
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011172" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011173" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011174endfun
11175
11176" ---------------------------------------------------------------------
11177" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11178fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011179" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011180 if exists("s:netrw_usercul")
11181 let &l:cursorline = s:netrw_usercul
11182 endif
11183 if exists("s:netrw_usercuc")
11184 let &l:cursorcolumn = s:netrw_usercuc
11185 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011186" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011187" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11188endfun
11189
Christian Brabandt62f7b552024-06-23 20:23:40 +020011190" s:RestoreRegister: restores all registers given in the dict {{{2
11191fun! s:RestoreRegister(dict)
11192 for [key, val] in items(a:dict)
11193 if key == 'unnamed'
11194 let key = ''
11195 endif
11196 call setreg(key, val[0], val[1])
11197 endfor
11198endfun
11199
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011200" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011201" s:NetrwDelete: Deletes a file. {{{2
11202" Uses Steve Hall's idea to insure that Windows paths stay
11203" acceptable. No effect on Unix paths.
11204" Examples of use: let result= s:NetrwDelete(path)
11205fun! s:NetrwDelete(path)
11206" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11207
Bram Moolenaar5c736222010-01-06 20:54:52 +010011208 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011209 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011210 if exists("+shellslash")
11211 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011212 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011213 let result = delete(path)
11214 let &shellslash = sskeep
11215 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011216" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011217 let result= delete(path)
11218 endif
11219 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011220" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011221 let result= delete(path)
11222 endif
11223 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011224 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011225 endif
11226
11227" call Dret("s:NetrwDelete ".result)
11228 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011229endfun
11230
11231" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011232" s:NetrwBufRemover: removes a buffer that: {{{2s
11233" has buffer-id > 1
11234" is unlisted
11235" is unnamed
11236" does not appear in any window
11237fun! s:NetrwBufRemover(bufid)
11238" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11239" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11240" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11241" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11242" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11243
yasuda4dbb2662023-10-04 20:50:35 +020011244 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011245" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011246 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011247 endif
11248
11249" call Dret("s:NetrwBufRemover")
11250endfun
11251
11252" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011253" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011254fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011255" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011256" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011257
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011258 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011259 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11260 " If so, delete it.
11261 call s:NetrwBufRemover(bufnr("$"))
11262
Bram Moolenaar446cb832008-06-24 21:56:24 +000011263 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011264" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011265 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11266 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11267 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11268 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11269 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11270 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11271 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11272 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11273 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11274 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11275 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11276 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11277 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11278 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11279 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11280 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11281
Bram Moolenaar85850f32019-07-19 22:05:51 +020011282 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011283" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011284 " when tree listing uses file TreeListing... a new buffer is made.
11285 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011286 " COMBAK: this causes a problem, see P43
11287" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011288 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011289 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011290 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011291" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011292 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011293
Bram Moolenaar446cb832008-06-24 21:56:24 +000011294 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011295" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011296 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11297 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11298 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11299 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11300 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11301 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11302 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11303 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11304 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11305 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11306 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11307 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11308 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11309 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11310 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11311 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11312
Bram Moolenaar5c736222010-01-06 20:54:52 +010011313 if a:0 > 0
11314 let b:netrw_curdir= a:1
11315 if b:netrw_curdir =~ '/$'
11316 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011317 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011318 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011319 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011320 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11321 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011322 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011323 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011324 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011325 endif
11326 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011327 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11328 let &l:bexpr = "netrw#BalloonHelp()"
11329 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011330
Bram Moolenaar8d043172014-01-23 14:24:41 +010011331" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011332endfun
11333
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011334" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011335" s:NetrwExe: executes a string using "!" {{{2
11336fun! s:NetrwExe(cmd)
GuyBrushd7745ac2024-11-23 14:13:10 +010011337 if has("win32") && exepath(&shell) !~? '\v[\/]?(cmd|pwsh|powershell)(\.exe)?$' && !g:netrw_cygwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011338 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11339 set shell& shellcmdflag& shellxquote& shellxescape&
11340 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011341 try
11342 exe a:cmd
11343 finally
11344 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11345 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011346 else
11347 exe a:cmd
11348 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011349 if v:shell_error
11350 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11351 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011352endfun
11353
11354" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011355" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11356fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011357 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011358" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011359 let curbuf = bufnr("%")
11360 let curwin = winnr()
11361 let iwin = 1
11362 while iwin <= winnr("$")
11363 exe iwin."wincmd w"
11364 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11365 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11366 let winvars= w:
11367 break
11368 endif
11369 let iwin= iwin + 1
11370 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011371 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011372 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011373" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011374 for k in keys(winvars)
11375 let w:{k}= winvars[k]
11376 endfor
11377 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011378" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011379 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011380endfun
11381
Bram Moolenaara6878372014-03-22 21:02:50 +010011382" ---------------------------------------------------------------------
11383" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011384" Returns: 0=success
11385" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011386fun! s:NetrwLcd(newdir)
11387" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011388" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011389
Bram Moolenaar85850f32019-07-19 22:05:51 +020011390 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011391 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011392 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011393 catch /^Vim\%((\a\+)\)\=:E344/
11394 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11395 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011396 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011397 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11398 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011399 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011400 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11401 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011402 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011403 endif
11404 endif
11405 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011406 let err472= 1
11407 endtry
11408
11409 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011410 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11411 if exists("w:netrw_prvdir")
11412 let a:newdir= w:netrw_prvdir
11413 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011414 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011415" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011416 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011417" 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 +010011418 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011419 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011420" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11421 return -1
11422 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011423
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011424" call Decho("getcwd <".getcwd().">")
11425" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011426" call Dret("s:NetrwLcd 0")
11427 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011428endfun
11429
Bram Moolenaar9964e462007-05-05 17:54:07 +000011430" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011431" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11432" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11433fun! s:NetrwSaveWordPosn()
11434" call Dfunc("NetrwSaveWordPosn()")
11435 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11436" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11437endfun
11438
11439" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011440" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11441" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11442fun! s:NetrwHumanReadable(sz)
11443" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11444
11445 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011446 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011447 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11448 elseif a:sz >= 10000000
11449 let sz = printf("%d",a:sz/1000000)."m"
11450 elseif a:sz >= 1000000
11451 let sz = printf("%.1f",a:sz/1000000.0)."m"
11452 elseif a:sz >= 10000
11453 let sz = printf("%d",a:sz/1000)."k"
11454 elseif a:sz >= 1000
11455 let sz = printf("%.1f",a:sz/1000.0)."k"
11456 else
11457 let sz= a:sz
11458 endif
11459
11460 elseif g:netrw_sizestyle == 'H'
11461 if a:sz >= 1073741824
11462 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11463 elseif a:sz >= 10485760
11464 let sz = printf("%d",a:sz/1048576)."M"
11465 elseif a:sz >= 1048576
11466 let sz = printf("%.1f",a:sz/1048576.0)."M"
11467 elseif a:sz >= 10240
11468 let sz = printf("%d",a:sz/1024)."K"
11469 elseif a:sz >= 1024
11470 let sz = printf("%.1f",a:sz/1024.0)."K"
11471 else
11472 let sz= a:sz
11473 endif
11474
11475 else
11476 let sz= a:sz
11477 endif
11478
11479" call Dret("s:NetrwHumanReadable ".sz)
11480 return sz
11481endfun
11482
11483" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011484" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11485" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11486fun! s:NetrwRestoreWordPosn()
11487" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011488 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011489" call Dret("NetrwRestoreWordPosn")
11490endfun
11491
11492" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011493" s:RestoreBufVars: {{{2
11494fun! s:RestoreBufVars()
11495" call Dfunc("s:RestoreBufVars()")
11496
11497 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11498 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11499 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11500 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11501 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11502 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11503
11504" call Dret("s:RestoreBufVars")
11505endfun
11506
11507" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011508" s:RemotePathAnalysis: {{{2
11509fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011510" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011511
Bram Moolenaara6878372014-03-22 21:02:50 +010011512 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011513 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011514 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011515 let s:user = substitute(a:dirname,dirpat,'\3','')
11516 let s:machine = substitute(a:dirname,dirpat,'\4','')
11517 let s:port = substitute(a:dirname,dirpat,'\5','')
11518 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011519 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011520 if s:machine =~ '@'
11521 let dirpat = '^\(.*\)@\(.\{-}\)$'
11522 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11523 let s:machine = substitute(s:machine,dirpat,'\2','')
11524 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011525
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011526" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11527" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11528" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11529" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11530" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11531" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011532
11533" call Dret("s:RemotePathAnalysis")
11534endfun
11535
11536" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011537" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11538" Returns status
11539" Runs system() on
11540" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011541" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011542fun! s:RemoteSystem(cmd)
11543" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11544 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011545 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 +000011546 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011547 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011548 else
11549 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11550 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11551 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011552 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011553 else
11554 let cmd= cmd.' '
11555 endif
11556 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011557" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011558 let ret= system(cmd)
11559 endif
11560" call Dret("s:RemoteSystem ".ret)
11561 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011562endfun
11563
11564" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011565" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011566fun! s:RestoreWinVars()
11567" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011568 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011569 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11570 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11571 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11572 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11573 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11574 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11575 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11576 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11577 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11578 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11579 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11580 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011581 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11582 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011583 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11584 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11585 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11586" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011587endfun
11588
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011589" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011590" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11591"
11592" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11593" is true) and a command, :Rexplore, which call this function.
11594"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011595" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011596"
11597" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011598fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011599 if exists("s:netrwdrag")
11600 return
11601 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011602" 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 +010011603" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11604" 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 +010011605
11606 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011607 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011608" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011609 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011610 unlet w:netrw_rexfile
11611" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011612 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011613" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011614" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11615" 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 +020011616 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011617
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011618 " ---------------------------
11619 " :Rex issued while in a file
11620 " ---------------------------
11621
Bram Moolenaara6878372014-03-22 21:02:50 +010011622 " record current file so :Rex can return to it from netrw
11623 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011624" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011625
11626 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011627" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011628 return
11629 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011630" 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 +020011631 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011632 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011633 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011634 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011635 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011636 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011637 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011638 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011639 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011640" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11641 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011642" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11643 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011644 if exists("s:rexposn_".bufnr('%'))
11645 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011646 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011647 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011648" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011649 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011650
Bram Moolenaar85850f32019-07-19 22:05:51 +020011651 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11652 if exists("s:explore_match")
11653 exe "2match netrwMarkFile /".s:explore_match."/"
11654 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011655 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011656
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011657" 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 +010011658" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011659endfun
11660
11661" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011662" s:SaveBufVars: save selected b: variables to s: variables {{{2
11663" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011664fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011665" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011666
11667 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11668 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11669 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11670 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11671 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11672 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11673
11674" call Dret("s:SaveBufVars")
11675endfun
11676
11677" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011678" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11679fun! s:SavePosn(posndict)
11680" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11681
Bram Moolenaar85850f32019-07-19 22:05:51 +020011682 if !exists("a:posndict[bufnr('%')]")
11683 let a:posndict[bufnr("%")]= []
11684 endif
11685" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11686 call add(a:posndict[bufnr("%")],winsaveview())
11687" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011688
11689" call Dret("s:SavePosn posndict")
11690 return a:posndict
11691endfun
11692
11693" ---------------------------------------------------------------------
11694" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11695fun! s:RestorePosn(posndict)
11696" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011697 if exists("a:posndict")
11698 if has_key(a:posndict,bufnr("%"))
11699" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11700 let posnlen= len(a:posndict[bufnr("%")])
11701 if posnlen > 0
11702 let posnlen= posnlen - 1
11703" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11704 call winrestview(a:posndict[bufnr("%")][posnlen])
11705 call remove(a:posndict[bufnr("%")],posnlen)
11706" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11707 endif
11708 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011709 endif
11710" call Dret("s:RestorePosn")
11711endfun
11712
11713" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011714" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011715fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011716" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011717 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11718 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11719 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11720 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11721 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11722 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11723 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11724 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11725 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11726 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11727 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11728 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11729 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11730 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11731 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11732 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11733 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11734 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11735" call Dret("s:SaveWinVars")
11736endfun
11737
11738" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011739" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011740" To allow separate windows to have their own activities, such as
11741" Explore **/pattern, several variables have been made window-oriented.
11742" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011743" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011744" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011745fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011746" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011747 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11748 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11749 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11750 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11751 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11752 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11753 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11754 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11755 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11756 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11757" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011758endfun
11759
11760" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011761" s:SetRexDir: set directory for :Rexplore {{{2
11762fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011763" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011764 let w:netrw_rexdir = a:dirname
11765 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011766 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011767" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11768" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011769" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011770" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011771" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011772endfun
11773
11774" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011775" s:ShowLink: used to modify thin and tree listings to show links {{{2
11776fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011777 if exists("b:netrw_curdir")
Christian Brabandt5c42c772024-12-12 19:13:08 +010011778 keepp :norm! $?\a
11779 "call histdel("/",-1)
Tom Benham64a536d2024-11-07 21:15:03 +010011780 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11781 let basedir = s:NetrwTreePath(w:netrw_treetop)
11782 else
11783 let basedir = b:netrw_curdir.'/'
11784 endif
11785 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011786 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011787 if resname =~ '^\M'.basedir
11788 let dirlen = strlen(basedir)
11789 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011790 endif
11791 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011792 setl noro ma
11793 call setline(".",modline)
11794 setl ro noma nomod
11795 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011796endfun
11797
11798" ---------------------------------------------------------------------
11799" s:ShowStyle: {{{2
11800fun! s:ShowStyle()
11801 if !exists("w:netrw_liststyle")
11802 let liststyle= g:netrw_liststyle
11803 else
11804 let liststyle= w:netrw_liststyle
11805 endif
11806 if liststyle == s:THINLIST
11807 return s:THINLIST.":thin"
11808 elseif liststyle == s:LONGLIST
11809 return s:LONGLIST.":long"
11810 elseif liststyle == s:WIDELIST
11811 return s:WIDELIST.":wide"
11812 elseif liststyle == s:TREELIST
11813 return s:TREELIST.":tree"
11814 else
11815 return 'n/a'
11816 endif
11817endfun
11818
11819" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011820" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11821" Solution from Nicolai Weibull, vim docs (:help strlen()),
11822" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011823fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011824" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11825
11826 if v:version >= 703 && exists("*strdisplaywidth")
11827 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011828
Bram Moolenaar8d043172014-01-23 14:24:41 +010011829 elseif type(g:Align_xstrlen) == 1
11830 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11831 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832
Bram Moolenaar8d043172014-01-23 14:24:41 +010011833 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011834 " number of codepoints (Latin a + combining circumflex is two codepoints)
11835 " (comment from TM, solution from NW)
11836 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837
Bram Moolenaar8d043172014-01-23 14:24:41 +010011838 elseif g:Align_xstrlen == 2
11839 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011840 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11841 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011842 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011843
Bram Moolenaar8d043172014-01-23 14:24:41 +010011844 elseif g:Align_xstrlen == 3
11845 " virtual length (counting, for instance, tabs as anything between 1 and
11846 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011847 " preceded by lam, one otherwise, etc.)
11848 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011849 let modkeep= &l:mod
11850 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011851 call setline(line("."),a:x)
11852 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011853 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011854 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011855 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011856
Bram Moolenaar446cb832008-06-24 21:56:24 +000011857 else
11858 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011859 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011860 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011861" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011862 return ret
11863endfun
11864
11865" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011866" s:ShellEscape: shellescape(), or special windows handling {{{2
11867fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011868 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011869 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011870 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011871 let f = a:0 > 0 ? a:1 : 0
11872 return shellescape(a:s, f)
11873endfun
11874
11875" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011876" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011877fun! s:TreeListMove(dir)
11878" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011879 let curline = getline('.')
11880 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11881 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11882 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11883 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11884 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11885 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11886" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11887" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11888" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11889" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11890" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11891 " COMBAK : need to handle when on a directory
11892 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011893 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011894 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011895 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011896 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011897" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011898 elseif a:dir == '[]' && nxtline != ''
11899 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011900" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011901 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11902 if nl != 0
11903 NetrwKeepj norm! k
11904 else
11905 NetrwKeepj norm! G
11906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011907" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011908 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011909 endif
11910
11911" call Dret("s:TreeListMove")
11912endfun
11913
11914" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011915" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11916" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11917" can't be called except via emenu. But due to locale, that menu line may not be called
11918" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11919fun! s:UpdateBuffersMenu()
11920" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011921 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011922 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011923 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011924 catch /^Vim\%((\a\+)\)\=:E/
11925 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011926 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011927 endtry
11928 endif
11929" call Dret("s:UpdateBuffersMenu")
11930endfun
11931
11932" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011933" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011934" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011935fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011936" call Dfunc("s:UseBufWinVars()")
11937 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011938 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11939 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11940 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11941 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11942 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11943 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11944 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11945 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11946 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 +000011947" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011948endfun
11949
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011950" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" s:UserMaps: supports user-defined UserMaps {{{2
11952" * calls a user-supplied funcref(islocal,curdir)
11953" * interprets result
11954" See netrw#UserMaps()
11955fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011956 if !exists("b:netrw_curdir")
11957 let b:netrw_curdir= getcwd()
11958 endif
11959 let Funcref = function(a:funcname)
11960 let result = Funcref(a:islocal)
11961
11962 if type(result) == 1
11963 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011964 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011965 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011967 exe result
11968 endif
11969
11970 elseif type(result) == 3
11971 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011972 for action in result
11973 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011974 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011975 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011976 exe action
11977 endif
11978 endfor
11979 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980endfun
11981
Bram Moolenaar85850f32019-07-19 22:05:51 +020011982" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011983" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011984" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011985let &cpo= s:keepcpo
11986unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011987
Bram Moolenaar85850f32019-07-19 22:05:51 +020011988" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011989" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011990" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011991" vim:ts=8 fdm=marker